NaN Issue -parseInt() throwing NaN for '08' and '09' number.

Community Alums
Not applicable
 
NaN issue has been observed when parsing a value '08' or '09' by using parseInt() . Though the existing logic was working fine for value between '01' to '07' number range. For ex. I have tried this sample code in background script of servicenow instance.
 
1) var a='09';
var b=parseInt(a);
gs.info(b);
 
Result: NaN.
 
2) var a='06';
var b=parseInt(a);
gs.info(b);
 
Result: 6.
 
Could you please suggest the work around or solution for above NaN issue?
 
3 REPLIES 3

Jaspal Singh
Mega Patron
Mega Patron

Hi,

Did you try using parseFloat() instead of parseInt() for a check.

OlaN
Giga Sage
Giga Sage

Hi,

By forcing parseInt to use 10-base values, it can be done. Like this

var a='09';
var b=parseInt(a, 10);
gs.info(b);

// output is 9

For more information on why this is happening, visit w3schools