Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Need bigger datatype in JavaScript

 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic