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 / General / March 2007

Tip: Looking for answers? Try searching our database.

How to get the simplest NumberFormats

Thread view: 
Philipp - 12 Mar 2007 12:11 GMT
Hello
I would like to format numbers (doubles) for display. I want to use the
methods NumberFormat.setMinimumFractionDigits() for rounding, but I am
annoyed by the Locale.
How can I get rid of the Locale formatting and get back a simple number
format (with a dot as decimal separator).

Expected: 1234567.89
US: 1,234,567.89
My Own Locale: 1'234'567.89

How to get rid of all these ' and , ?

Thanks Phil
Robert Klemme - 12 Mar 2007 12:24 GMT
> Hello
> I would like to format numbers (doubles) for display. I want to use the
[quoted text clipped - 10 lines]
>
> Thanks Phil

Please read the API docs.  IIRC you can set a Locale on creation (or
later).  You can also explicitly set the formatting symbols.

Kind regards

    robert
Philipp - 12 Mar 2007 12:30 GMT
> Hello
> I would like to format numbers (doubles) for display. I want to use the
[quoted text clipped - 8 lines]
>
> How to get rid of all these ' and , ?

Ok I got my solution. Sorry for the noise.

myFormat = new DecimalFormat("##0.#####E0");

does what I want (which is not the example I wrote above, but I know that).

But I can't understand why in the JavaDoc (at
http://java.sun.com/j2se/1.4.2/docs/api/java/text/DecimalFormat.html)
they say not to instanciate this class directly but to use the factory
method from NumberFormat.

I can't apply a pattern if I don't know if it is a DecimalFormat. In the
doc they say to do this:
NumberFormat f = NumberFormat.getInstance(loc);
 if (f instanceof DecimalFormat) {
     ((DecimalFormat) f).setDecimalSeparatorAlwaysShown(true);
 }

but what do you do if "f" is not an instanceOf DecimalFormat? Are you
suppose to die of a sudden death?

Phil


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.