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 / September 2004

Tip: Looking for answers? Try searching our database.

Hiding symbol with Currency Format

Thread view: 
wenyb - 29 Sep 2004 08:06 GMT
I use NumberFormat.getCurrencyInstance to get a formatter to display
amounts. It automatically shows the amount with the currency symbol. I
want amounts to be display in a column but without the symbol. Is it
possible to do this simply ?

Thanks.
Paul Lutus - 29 Sep 2004 08:22 GMT
> I use NumberFormat.getCurrencyInstance to get a formatter to display
> amounts. It automatically shows the amount with the currency symbol. I
> want amounts to be display in a column but without the symbol. Is it
> possible to do this simply ?

Don't use NumberFormat.getCurrencyInstance(), instead use DecimalFormat.

Like this:

import java.text.*;

public class Test {
 
 
  public static void main(String[]args)
  {
     DecimalFormat fmt = new DecimalFormat("#,##0.00;(#,##0.00)");
     double x = 0.01;
     for(int i = 0;i < 12;i++) {
        System.out.println(fmt.format(x));
        x *= 10.0;
     }
  }
}

Result:

0.01
0.10
1.00
10.00
100.00
1,000.00
10,000.00
100,000.00
1,000,000.00
10,000,000.00
100,000,000.00
1,000,000,000.00

Signature

Paul Lutus
http://www.arachnoid.com

Lothar Kimmeringer - 29 Sep 2004 10:32 GMT
> Don't use NumberFormat.getCurrencyInstance(), instead use DecimalFormat.

Not good.

>       DecimalFormat fmt = new DecimalFormat("#,##0.00;(#,##0.00)");

Only works for a subset of all available currencies.

Gruesse, Lothar
Signature

Lothar Kimmeringer                E-Mail: spamfang@kimmeringer.de
              PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
                questions!

RobM - 29 Sep 2004 12:02 GMT
> I use NumberFormat.getCurrencyInstance to get a formatter to display
> amounts. It automatically shows the amount with the currency symbol. I
> want amounts to be display in a column but without the symbol. Is it
> possible to do this simply ?
>
> Thanks.

Hi - you could try numberformat.getNumberInstance and use the function
setMinimumFractionDigits(2)

HTH
Rob
wenyb - 29 Sep 2004 18:37 GMT
wenyb a écrit :
> I use NumberFormat.getCurrencyInstance to get a formatter to display
> amounts. It automatically shows the amount with the currency symbol. I
> want amounts to be display in a column but without the symbol. Is it
> possible to do this simply ?
>
> Thanks.

Thanks for the answers.

Using DecimalFormat is indeed not good for the reason given by Lothar
Kimmeringer.

I found a way by calling setPositivePrefix("") and setPositiveSuffix("")
on the format returned by getCurrencyFormat. But I wonder if it covers
all the cases.

Thanks.
wenyb - 30 Sep 2004 22:05 GMT
wenyb a écrit :
> wenyb a écrit :
>
[quoted text clipped - 15 lines]
>
> Thanks.

For interested people, found a cleaner way using
DecimalFormatSymbols.setCurrencySymbol("")


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.