all groups > vj# > july 2005 >
You're in the

vj#

group:

java.text.DecimalFormat


java.text.DecimalFormat Andy W.
7/20/2005 9:31:02 AM
vj#: Hi,

The following piece of code is producing an odd result. Upon execution
s1="2199.76" whilst strangely s2="2199.77".

java.text.DecimalFormat DF = new java.text.DecimalFormat("#,##0.00", new
DecimalFormatSymbols( Locale.US ) );

double d1 = 2199.76;
String s1 = DF.format( d1 );

double d2 = 2199.7599999999998;
String s2 = DF.format( d2 );

Does anyone have any thoughts on why this is the case? Is it simply a bug in
DecimalFormat?

Re: java.text.DecimalFormat Lars-Inge Tønnessen [VJ# MVP]
7/21/2005 8:46:53 PM

[quoted text, click to view]

Yes, most likely. They should give the same result.



Regards,
Lars-Inge Tønnessen

AddThis Social Bookmark Button