+6 votes

Hello Team,

I would like to share with you a problem I encountered yesterday.
If, like me, you never worked on old version of Javascript, with old browser, you could be used to do that :

parseInt("011") // return 11

But Efficy use not the same version of Javascript as your browser. He use a version before ECMA5.

So, this :

parseInt("011") // return 9

The explanation is simple. Before ES5, the base used by default was not always 10 (it was depending the string you wanted to parse). The documentation is clear about that : parseInt sur MDN

So the solution is :

parseInt("011", 10) // return 11

Or, even better, the Efficy function :

strToFloat("011") // ALWAYS return 11

I hope you won't spend as much time as I did :)

Loïc

asked in WorkFlow / Serverscript by (531 points)
edited by
I'm feeling old now, I did work with these old browsers :-)
Important to add is that Efficy serverside still uses an old ECMA version, to be more specific, it's JScript
Never forget the base !  For me parseInt("011", 10)   is the rigth solution for every case
You should indeed always explicitely set the base, this is what we do in the standard code anyway :)

Please log in or register to answer this question.

1,249 questions
1,519 answers
1,859 comments
328 users