wood burning stoves 2.0*
The moose likes Java in General and the fly likes formatting number Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "formatting number" Watch "formatting number" New topic
Author

formatting number

Amol Juvatkar
Greenhorn

Joined: May 16, 2005
Posts: 16
hi ,
i want to display number as format 99,99,999.99

I am using DecimalFormat("##,##,###.00")

but sill it is showing output as 9,999,999.99

kindly suggest me if there is another solution.

my code is like this,



thanks,
Amol
Srinivas Kalvala
Ranch Hand

Joined: Oct 20, 2005
Posts: 257

Hello,

See the Java Source for DecimalFormat(String) Parameter Constructor. It depends on the Locale Object.




So, change your locale and try it.
Tim LeMaster
Ranch Hand

Joined: Aug 31, 2006
Posts: 226
From ye old JavaDoc -

The grouping separator is commonly used for thousands, but in some countries it separates ten-thousands. The grouping size is a constant number of digits between the grouping characters, such as 3 for 100,000,000 or 4 for 1,0000,0000. If you supply a pattern with multiple grouping characters, the interval between the last one and the end of the integer is the one that is used. So "#,##,###,####" == "######,####" == "##,####,####".
Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
That's not going to help. Read the DecimalFormat documentation, specifically this excerpt:


The grouping separator is commonly used for thousands, but in some countries it separates ten-thousands. The grouping size is a constant number of digits between the grouping characters, such as 3 for 100,000,000 or 4 for 1,0000,0000. If you supply a pattern with multiple grouping characters, the interval between the last one and the end of the integer is the one that is used. So "#,##,###,####" == "######,####" == "##,####,####".


It would appear that what you hope to accomplish isn't possible with DecimalFormat. The last grouping in the format is used for all groupings, if you want them to be different I guess you'll have to find one or roll your own.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38519
    
  23
I agree you aren't using a standard thousands separator format.

If all else fails, try integer division and remainder operators. But make sure you don't stray outwith the bounds of the int type:-

Or try using the Double class to change the number to a String, and split it into a char[] array, then print them one by one with commas as appropriate. You will have to count the digits in your numbers carefully for both methods otherwise you will get something like, "0,01,234.56."
Amol Juvatkar
Greenhorn

Joined: May 16, 2005
Posts: 16
Thanks for your help.

regards
Amol
Alan Moore
Ranch Hand

Joined: May 06, 2004
Posts: 262
Here's a regex implementation of Campbell's second suggestion:
Amol Juvatkar
Greenhorn

Joined: May 16, 2005
Posts: 16
Thanks Alan,

now one more doubt.



with
statement 1 formatting doesn't work.
but
with statement 2 it works properly.

in general both are strings only.
so what may be wrong ??

regards,
amol
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: formatting number