cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

parseInt() not working for '08' and '09'. Why?

Janakiraman-P
15-Moonstone

parseInt() not working for '08' and '09'. Why?

Hi,

 

Its really confusing, why parseInt('08') is giving NaN? 

parseInt('010') is 8?

parseInt('0101') is 65?

Is it working  on the basis of Binary?

but in JS it is working correctly.

 

 

Clarify Please,

 

 

Regards,

Janakiraman P

ACCEPTED SOLUTION

Accepted Solutions

You are correct, the JAR is named custom-rhino-js-5.1.0.jar in your version of ThingWorx.

It is apparently based on rhino 1.7R4 (as per MANIFEST.MF). This version is from 2012, it apparently complies to ECMAScript 3 + JavaScript 1.7 and some regex feature from JavaScript 1.8.

Regards,

Stéphane

View solution in original post

6 REPLIES 6

Hi Janakiraman 

  • Javascript consider numbers that start with 0 to be octal
  • 08 and 09 are not valid octal numbers

See also https://stackoverflow.com/questions/850341/how-do-i-work-around-javascripts-parseint-octal-behavior

-- sma

 

Hi,

I understood the problem.

 

in JavaScript it is working fine.

 

parseInt(string, radix);

 

If the input string begins with "0" (a zero), radix is assumed to be 8 (octal) or 10 (decimal). Exactly which radix is chosen is implementation-dependent. ECMAScript 5 clarifies that 10 (decimal) should be used, but not all browsers support this yet. For this reason always specify a radix when using parseInt.

 

But the problem has been resolved in ECMAScript 5.

 

Is Thingworx using ECMAScript 3 ?

 

 

 

Regards,

Janakiraman P

 

 

Rhino is used as Javascript engine for ThingWorx Service.

To identify the version of Rhino used in your version of ThingWorx, look a the rhino JAR filename in <Tomcat>\webapps\Thingworx\WEB-INF\lib\

 

Regards.

Hi,

The specified JAR is not available at <Tomcat>\webapps\Thingworx\WEB-INF\lib\

 

Am using Thingworx 8.4.2. Not sure which version of JavaScript is used.

 

 

regards,

Janakiraman P

You are correct, the JAR is named custom-rhino-js-5.1.0.jar in your version of ThingWorx.

It is apparently based on rhino 1.7R4 (as per MANIFEST.MF). This version is from 2012, it apparently complies to ECMAScript 3 + JavaScript 1.7 and some regex feature from JavaScript 1.8.

Regards,

Stéphane

Hi,

 

Okay, Thanks for your solution.

 

The error (NaN) because of ECMAScript 3, so here 

parseInt(string, radix);

radix is Octal by default in Thingworx.

 

 

Thanks 

Janakiraman P

Announcements


Top Tags