Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Round off a number  RSS feed

 
sreeni san
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I have data coming in like 42.44, 28.69, 28.89, 22.22, etc., I need to round these numbers up for 0.5, like the result of rounding off the above numbers should be 42.50, 29.0, 29.0, 22.50. How do I do it?
The above numbers are of type double.
Thanks in advance
Sreeni.
 
rom chatterjee
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the documentation for java.lang.Math (you should try the round() and floor() methods).
Come back if you are still having problems
 
sreeni san
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using round() or floor() will not help me as round() would round off 42.44 to 42 and floor() will also round 42.44 to 42. In case the number 28.69, the round() would round off to 29 and floor() to 28.
This is not I want, I want the numbers to get rounded up to next 0.50 as mentioned in the examples in my question.
 
Tom Blough
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this:
 
rom chatterjee
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My apologies.
This tech tip from Sun seems to cover what you are trying to do. I shall check back to if this still isn't what you need.
 
Elouise Kivineva
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where did you find a round method that takes 2 parameters?
 
Tom Blough
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Elouise Kivineva:
Where did you find a round method that takes 2 parameters?

If you are referring to:

I wrote it - look a little farther down in the code.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!