I feel your pain, Ambika, really I do... This is the reason my output stylesheets
are riddled with format-number(). <xsl:value-of
select="format-number(number(@AIR_CHARGES), '#,##0.00')" /> and <xsl:variable
name=’roundedValue’ select=’format-number(number($rawValue), “0.00”)’
/> But in my case, I know I am working with
dollars/cents, so I know what my output precision should be. I fully
appreciate that in other cases, it may not be so clearly defined. The same kind of behavior exists in
languages that have ‘float’ and ‘double’ types (C, C++,
Java, etc, probably Pascal’s “real” type too). To
combat this for currency values, I convert them to the biggest integer type and
process them as cents: 32-bit long in “old C”, 64-bit long in Java,
and “long long” on modern C/C++ compilers. At least then you
are in complete control of your math. Java also has java.math.BigDecimal
which doesn’t do the IEEE-754 behavior either, but it has the overhead of
being a java.lang.Object subclass, whereas the primitive integers/longs work
faster. I have never understood how people can
accept this rounding over the years, but these are my workarounds.
|
- Error/Bug adding floating point numbers Daniel Thommes
- Re: Error/Bug adding floating point numbers keshlam
- RE: Error/Bug adding floating point numbers Timothy Jones