• Post Reply Bookmark Topic Watch Topic
  • New Topic

round up double numbers to desired value?  RSS feed

 
Winston Liek
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I have a double/big decimal value with 2 decimal places....What I want is that if decimal value is .01 - .49, it should round up to 0.50.
Then if decimal value is between 0.51 - 0.98, it will round up to 0.99.

Is there a function in double that can do this? How can I do this? TIA
 
Brian Barrick
Ranch Hand
Posts: 67
Android Java
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no standard form of rounding which will give you those results. I think you will have to write your own algorithm.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!