Alright, seems Google Script interpretes leading zero numbers in a string as octal, when no radix is defined, while other JS-implementations don't.
Octal interpretations with no radix <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt#Octal_interpretations_with_no_radix> Easy fix is to add the radix (as recommended in the specs - doh!). function test_parse_int() { var ss = SpreadsheetApp.getActiveSpreadsheet(); // parses to 7 ss.toast( parseInt("07") , 10 ); // parses correctly to 8 now ss.toast( parseInt("08") , 10 ); } Am Montag, 4. Juni 2018 07:05:32 UTC+2 schrieb Oliver Reischl: > > I'm trying to convert a string to an int. When the string is a number with > a leading zero, it seems Google Script gets into trouble. Converting "07" > to 7 works fine, converting "08" ends in a NaN. > > function test_parse_int() { > var ss = SpreadsheetApp.getActiveSpreadsheet(); > // parses to 7 > ss.toast( parseInt("07") ); > // parses to NaN ?!? > ss.toast( parseInt("08") ); > } > > > I tested that against JavaScript and there it works fine. > > <script> > // parses to 7 > document.writeln(parseInt("07")); > // parses to 8 > document.writeln(parseInt("08")); > </script> > > > This behaviour doesn't make any sense to me, is this a bug? Am i missing > something? > -- You received this message because you are subscribed to the Google Groups "Google Spreadsheets API" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
