Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

scaling a Double

 
Dave Jones
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ranchers!!

I have a few Double members, with setters and getters.
I recently received a request that the getters will return a double with only two digits after the decimal points(decimal digits, that is).
e.g - the number for the number 5.123 the getter will return will return 5.12.
Now, I remembered something called "scaling" , setScale , but I can't find this method in the Double object nor in the API.

I know I can always write a small util, but I always prefer something ready.

Any suggestions??
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like they really want a BigDecimal.
 
Manuel Leiria
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use Decimal Format

http://java.sun.com/j2se/1.4.2/docs/api/java/text/DecimalFormat.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic