Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

DecimalFormat drops the 0s after decimal point. I need to keep them.

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

I have to show the number as is without dropping the end 0s after decimal.

e.g. I need to show 12 as 12, 13.0 as 13.0 14.50 as 14.50. But the decimal format removes the last zero.

Unfortunately, JFreeChart tooltip logic requires a decimal format to be specified to do anything like this.

Any idea how we can achieve this.

thanks in advance.
 
author
Posts: 23956
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you mean by "I need to keep them"? Are you using DecimalFormat to parse a double from a string? And is now wondering why when you print the double, the format of the double is gone?

If you are... A double is a value. It contains no formatting what-so-ever. So, there is no such a thing as "keep them" -- any formatting is lost when the string is converted to a double.

Henry
 
Master Rancher
Posts: 4971
79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are you specifying the DecimalFormat now? Have you looked at the API for DecimalFormat? If it's something like

try instead
 
Sri Kor
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mike Simmons wrote:How are you specifying the DecimalFormat now? Have you looked at the API for DecimalFormat? If it's something like

try instead



I can't use formatting like this. Because, if I have a number like 29 I have to show it as 29 in the JFreeChart. If I use a format like the above, it will change the number 29 to 29.00.
 
Sri Kor
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:What do you mean by "I need to keep them"? Are you using DecimalFormat to parse a double from a string? And is now wondering why when you print the double, the format of the double is gone?

If you are... A double is a value. It contains no formatting what-so-ever. So, there is no such a thing as "keep them" -- any formatting is lost when the string is converted to a double.

Henry



By default a number like 12.20 is shown as 12.2. But, I need to show it as 12.20. If the number is 12.220, I need to show 12.220. But, JFreeChart which uses decimal format drops 0 at the end.
 
Sheriff
Posts: 22796
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could consider using BigDecimal. If you create that using "12.220" it will keep being 12.220, including when calling it's toString method.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic