Gwt - Arbitrary precision Float numbers on JavaScript

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

I have some inputs on my site representing floating point numbers with up to ten precision digits (in decimal). At some point, in the client side validation code, I need to compare a couple of those values to see if they are equal or not, and here, as you would expect, the intrinsics of IEEE754 make that simple check fails with things like (2.0000000000==2.0000000001) = true.

I may break the floating point number in two longs for each side of the dot, make each side a 64 bit long and do my comparisons manually, but it looks so ugly!

Any decent Javascript library to handle arbitrary (or at least guaranteed) precision float numbers on Javascript?

Thanks in advance!

PS: A GWT based solution has a ++

Answers

http://code.google.com/p/gwt-math/ http://code.google.com/p/gwt-math/

However, I warn you, it s a GWT jsni overlay of a java->javascript automated conversion of java.BigDecimal (actually the old com.ibm.math.BigDecimal).

It works, but speedy it is not. (Nor lean. It will pad on a good 70k into your project).

At my workplace, we are working on a fixed point simple decimal, but nothing worth releasing yet. :(

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/2108729/arbitrary-precision-float-numbers-on-javascript

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils