-2

The below javascript code is working fine in Internet Explorer but not working in Firefox and Google chrome

var prand=11211411110311410111511510511111068508491;
//This is the value of variable prand that i get after calculation 
prand =   parseInt(prand.substring(0, 10)) + parseInt(prand.substring(10, prand.length))).toString(); 
//After this calculation I'm getting the expected  result in IE,but the value is coming different in Firefox and Chrome

I have sorted out some more information ...

On alerting parseInt(prand.substring(10, prand.length)) , it's showing 232332021465786650000 on IE and 3.114101115115105e+29 on Chrome

Govind Singh
  • 15,282
  • 14
  • 72
  • 106
Kailas
  • 439
  • 1
  • 5
  • 14

1 Answers1

3

if you wish to use substring, make sure your original variable is a string. Chrome finds that your prand variable has no quotes, so it tries to convert it into the largest number. IE on the other hand gives up and uses it as a string instead. Try declaring your variable as a string:

var prand = "11211411110311410111511510511111068508491";

Even then, the value of 311410111511510511111068508491 is too big to fit into a single integer. You might want to rethink your logic.

ystan-
  • 1,474
  • 1
  • 19
  • 43
  • actually i'm getting the value 11211411110311410111511510511111068508491 to variable prand after a set of calculations.So its not possible to convert it to string – Kailas Mar 20 '14 at 05:46
  • It's still a number in IE8. Which IE did you test it with? – sabof Mar 20 '14 at 05:49