• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Setting DecimalFormat grouping

 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I want to show the following number:
10000000.00
As:
1,00,00,000.00

I have already tried the following:


The output is not as expected it shows: 10,000,000.00

Any suggestions please?

Regards,
Mehul.
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What about trying:


There seems to be no sense in setting the Locale if you are setting the format of the number.
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unless the way to format numbers according to the custom of that locale is the desired

"#,##,##,###.00"
[ March 29, 2005: Message edited by: Carol Enderlin ]
 
Mehul Sanghvi
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thanks for the responses.
After your suggestions, I did try the following:

But it still doesnt work!
The output is still: 10,000,000.00

Regards,
Mehul.
 
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 "#,##,###,####" == "######,####" == "##,####,####".



Taken form Java 1.4.2 API - DecimalFormat.java

Ren�
[ March 31, 2005: Message edited by: Rene Larsen ]
 
Ranch Hand
Posts: 489
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It wouldnt work. The reason is that the DecimalFormat wouldnt format your object in any random fashion you desire. Each and every DecimalFormat object is associated to a DecimalFormatSymbols object which define the grouping seperator, thousands seperator symbols etc.

Thus when you specify a pattern in this fashion ##,###.##, you specify that your thousand seperator is a comma and decimal seperator is a dot. By specifying a comma after every numerical digit, you cannot for instance, force the formatter to overthrow it's thousand count which will remain constant at the number of places reserved for that locale.(3 for english locale etc)

You would have to write custom code to format in the way you desire.

ram.
 
Mehul Sanghvi
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thanks again for the suggestions.

I was trying to write some of my own code as Ram has suggested.

But the moment I tried to write a class as:

It says "cannot override a final method"!

Alternatively I can use composition, provide my implementation to this one method and delegate rest of the calls.
What I am now confused is why would the API writers not want anyone to extend DecimalFormat??

Thanks again!

Regards,
Mehul.
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try to use theses classes... it will probably do what you need. I've created it to replace the JFormattedTextField.

To solve your problem, use the class NumericTextField to handle numbers.

TextFields

If you have any suggestion, mail me.
reply
    Bookmark Topic Watch Topic
  • New Topic