• 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

Double.toString

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Why Double.toString(0.0050) give me "0.0050" but
Double.toString(0.0150) return me "0.015" ?
Anyone can explain this, thank you.
Rgds
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure, offhand. So, I peaked at the source code, and discovered that FloatingDecimal is responsible for most of the nitty-gritty work of creating the String. The details of the conversion was a bit more than I felt like digesting this afternoon.
You might want to take a look at the source code of the Double and FloatingDecimal classes. Note that the source code for most (and perhaps all) of the J2SE classes is usually included in a file named src.jar or src.zip in the J2SDK installation.
Of course, if you're trying to figure out a more consistent and controllable way of formatting the displaying of a double value, then I'd suggest taking a look at the java.text.DecimalFormat class.
Good luck.
[ April 13, 2003: Message edited by: Dirk Schreckmann ]
 
Come have lunch with me Arthur. Adventure will follow. This tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic