| Author |
Need bigger datatype in JavaScript
|
Kinjal Sonpal
Ranch Hand
Joined: Jun 06, 2003
Posts: 96
|
|
Hi All, I'm presenting a form to the user where the user needs to enter a pretty large numbers. I'm also supposed to perform some client-side calculation (some simple multiplications) on the data, display the result to the user and then only proceed further if the user confirms. Now the problem is that when I perform the calculations (I'm not using any math functions), it seems the result is much bigger and hence the data wraps around (some thing similar to what used to happen in some of the older C/C++ compilers). Any suggestions or work arounds? Regards, Kinjal Sonpal
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15003
|
|
I do not know how big of numbers you are talking here but: http://www.leemon.com/crypto/BigInt.html Eric
|
 |
Kinjal Sonpal
Ranch Hand
Joined: Jun 06, 2003
Posts: 96
|
|
Eric, Thanks for the prompt reply. The solution seems to be a little overwhelming for the magnitude of the problem. Second thing is that the numbers can also be floating point. And precision is based on data from a database, which travel through 3 J2EE based layers before it reaches the client browser. Another question has also sprung my mind. Has any one faced any data conversion and presicion loss problems while transferring the data? What say? Regards, Kinjal Sonpal
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15003
|
|
What are the numbers we are talking about here that are causing you trouble? Yes JavaScript has trouble with numbers because of using IEEE and limited bits...you can read here: http://help.netscape.com/kb/consumer/19970930-1.html If you are worried about JavaScript handling it, then you better do it all on server side... You might even want to look at this: http://radio.javaranch.com/channel/pascarello/2004/03/31.html Eric [ April 09, 2004: Message edited by: Eric Pascarello ]
|
 |
Kinjal Sonpal
Ranch Hand
Joined: Jun 06, 2003
Posts: 96
|
|
Eric, Thanks for the reply again. As you have pointed out here and in the blog, I'm planning to perform the calculations at the server-side. Now the results are supposed to be stored straight away and confirmation of results is a separate transaction. As for my second question about loss in conversion, so far there have been no issues. But I was just a little worried as I'm not really very experienced programmer and my data travels through different layers, there can be such a possibility. Do you advise me to take any special care? Regards, Kinjal Sonpal
|
 |
 |
|
|
subject: Need bigger datatype in JavaScript
|
|
|