aspose file tools*
The moose likes Beginning Java and the fly likes formatting amount Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "formatting amount" Watch "formatting amount" New topic
Author

formatting amount

Jas Oberai
Ranch Hand

Joined: Jan 16, 2005
Posts: 231
If I have a number like 120000,I am trying to format it like 1200.00.
I am using this function,but I am getting the result as 1,200.00.Can someone
please tell me what changes I have to make to get the desired results.Thanking you in
advance


SCJP 1.4 (88%)<br />SCWCD 1.4 (88%)
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
Try just using the DecimalFormat passing your own Format String instead of relying on the Local Based Currency Format


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Pete Tyo
Ranch Hand

Joined: May 11, 2005
Posts: 38
I want a class that I created to return a currency format i.e. (30.00 just two decimals at the end for cents) I have the print statement put the $ and dollars at the end.. The problem I am running into is using the below code suggested in this thread. My value is a double how to I convert it to a string? And is there anything in the main program I have to change since I will be passing back a string instead of a double?






Thanks,

Pete
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Don't know the formatting answer, but I'll chime in with this: Using doubles for money will make you unhappy in the long run. The rounding and truncation will not be what you expect. A decimal class or longs that keep the value in pennies (ie $1.00 == 100) are probably better choices.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Alan Jump
Greenhorn

Joined: May 25, 2005
Posts: 26
Originally posted by Pete Tyo:
I want a class that I created to return a currency format i.e. (30.00 just two decimals at the end for cents) I have the print statement put the $ and dollars at the end.. The problem I am running into is using the below code suggested in this thread. My value is a double how to I convert it to a string? And is there anything in the main program I have to change since I will be passing back a string instead of a double?


Instead of using DecimalFormat(), you could use String.format(), something like this:

It's a bit of a shortcut, but it would leave myValue untouched for further use, and still produce the desired output format.
Pete Tyo
Ranch Hand

Joined: May 11, 2005
Posts: 38
appreciate all the suggestions... Finally used the below code to get my desired output from a double...



Thanks,

Pete
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: formatting amount