0

I've tried to round numbers with the function round(123.5)

as expected, if it's 0.5 then it will round UP to the next number, if it's LESS THAN 0.5 then it will go to the lower number

so this is what I've done, until I found issue with the number 654.5 it should be round up to 655 but it's not, it became 654 !

enter image description here

is there something that I can do to make sure that any ##.5 will be round up ?

sulaiman
  • 311
  • 2
  • 3
  • 11
  • ```import math print(math.ceil(654.5))``` – David Meu Apr 25 '21 at 13:24
  • 1
    The note on the [`round()` docs](https://docs.python.org/3/library/functions.html#round): *"The behavior of `round()` for floats can be surprising: for example, `round(2.675, 2)` gives `2.67` instead of the expected `2.68`. __This is not a bug: it’s a result of the fact that most decimal fractions can’t be represented exactly as a float__. See [Floating Point Arithmetic: Issues and Limitations](https://docs.python.org/3/tutorial/floatingpoint.html#tut-fp-issues) for more information."* – Tomerikoo Apr 25 '21 at 13:41

0 Answers0