Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Visual J# / July 2005

Tip: Looking for answers? Try searching our database.

java.text.DecimalFormat

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andy W. - 20 Jul 2005 17:31 GMT
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?

Note that Sun's jvm produces "2199.76" for both strings.
Lars-Inge Tønnessen [VJ# MVP] - 21 Jul 2005 19:46 GMT
> Note that Sun's jvm produces "2199.76" for both strings.

> Is it simply a bug in DecimalFormat?

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

Regards,
Lars-Inge Tønnessen

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.