why ParseInt returning value in different format

Supriya25
Tera Guru

Hi All,

SCript Inlcude :

var SleepForScoppedApp = Class.create();
SleepForScoppedApp.prototype = {
    initialize: function() {},
    sleep: function(time) {
        gs.sleep(time);
    },
    type: 'SleepForScoppedApp'
};

 

System Property's :
name : holdforfewSeconds , type: integer  value : 10000
name : refreshseconds, type:integer value:3000

widget :

var ms = input.recheck ? parseInt(gs.getProperty('refreshseconds') :  parseInt(gs.getProperty('holdforfewSeconds');
gs.addInfoMessage(ms) ;

new global.SleepForScoppedApp().sleep(ms);



 

why Info Message coming like 10000.0         ???? why .0 coming after 10000




7 REPLIES 7

Tony Chatfield1
Kilo Patron

 

Hi, I believe ms is correct and the issue is a result of the conversion delivered via addInfoMessage(). 
A simple work around appears to be to stringify the value

var ms = parseInt('10000');
gs.info(ms);
gs.addInfoMessage(typeof ms);
gs.addInfoMessage(ms);
gs.addInfoMessage(ms.toString());
gs.addInfoMessage('test ' + ms);
gs.info(ms);




Hi @Tony Chatfield1 

 

var ms = parseInt('10000');

RESULTS :

gs.addInfoMessage(typeof ms);   // NUMBER
gs.addInfoMessage(ms);             // 10000.0
gs.addInfoMessage(ms.toString());   // 10000
gs.addInfoMessage('test  : ' + ms);      // test : 10000

 

 

 

gs.addInfoMessage(ms); // 10000.0
gs.addInfoMessage('test : ' + ms); // test : 10000

what is the difference in above addInfoMessage  seems to be both are same right ? then how come result coming in different way.
any suggestions  please  ?




I think that @Tony Chatfield1 is right, this has something to do with addInfoMessage. For some reason it looks like it's trying to detect what type of container is being passed. Very strange honestly.

Hi, looking at this further it is not addInfoMessage() which is at fault, but is simply expected behavior from parseInt() where a string is parsed and the Integer component of the string is returned as a 'number'

I suspect that you could need to take some time reviewing Javascript technical documentation in order to get an exact explanation, but this should be sufficient to confirm that it is expected behavior.

parseInt() - JavaScript | MDN (mozilla.org)
About halfway down the page it states. "Because parseInt() returns a number, it may suffer from loss of precision if the integer represented by the string is outside the safe range. "

you can confirm this simply via

var ms = parseInt('10000');

gs.info('typeof  ' + typeof ms);