Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / March 2006

Tip: Looking for answers? Try searching our database.

decimal format, how to not round

Thread view: 
John_Woo - 17 Mar 2006 03:08 GMT
Hi,

Pls look at the following:

       DecimalFormat format = new DecimalFormat("#,###.00");

       System.out.println(format.format(1234.999)); // 1,235.00

I'm wondering, how to make it NOT round?

--
Thanks
John
Toronto
Roedy Green - 17 Mar 2006 03:37 GMT
>Pls look at the following:
>
[quoted text clipped - 3 lines]
>
>I'm wondering, how to make it NOT round?

I don't think you can change it.  I would have to do it with pre or
post processing or rolling your own.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Oliver Wong - 17 Mar 2006 16:43 GMT
> Hi,
>
[quoted text clipped - 5 lines]
>
> I'm wondering, how to make it NOT round?

   It HAS to round, because the number of digits in the number to represent
exceeds the number of digits in the formatting mask. Perhaps instead you
wanted to ask how to change the rounding method (e.g. round to zero, round
away from zero, round down, round up, round to even, round to nearest)?

   - Oliver
Patricia Shanahan - 17 Mar 2006 16:45 GMT
> Hi,
>
[quoted text clipped - 10 lines]
> John
> Toronto

One technique is to convert to BigDecimal, "round" to the required scale
using the BigDecimal rounding mode you want, and then format that.

Patricia


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.