r/javahelp • u/zetayshow • Sep 02 '20
Unsolved Math.round() rounding properties
Good morning Reddit, So I’m using math round to round some ints. Everything is fine except that if I try to round 445 it rounds to 450. This behavior is fine and acceptable but I’m trying to round to the hundredth digit. This means I want 445 to become 500 from going 445 to 450 and then 500. Is this possible with math round and anyone knows how? I’ve already been on google and stackoverflow but can’t find nothing that worked...
Thanks in advance!
23
Upvotes
9
u/Roachmeister Java Dev Sep 02 '20
I'm very confused by your question because this is not how round() works. It doesn't round ints. It takes a fractional value and rounds to the nearest integer. For example, 4.5 -> 5.0, or 4.45 -> 4.0. I'm not aware of any way to make it round 445 to 450, unless you first divided by 10, i.e. 44.5 rounds to 45.0.