• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to increase decimal precision  RSS feed

 
Ravi Goli
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I've a question regarding precision for the float/double numbers in java.
For example: how to increase the precision for say the number 1.2 to 1.20
or 2.300 to 2.3000 so...

Thanks,
Ravi.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot "increase the precision" of float and double. However, your most likely don't really mean that you want to increase the precision - you just want to know how to print a float or double with more decimal digits. You can use class DecimalFormat to format numbers with the desired number of digits, or use printf(...) with an appropriate conversion pattern:
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have a standard warning about floating types: if you're thinking about decimal precision or handling money they probably don't do what you want to do. What is your application doing with these values?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!