F
F
freecam2021-07-14 15:16:37
Mathematics
freecam, 2021-07-14 15:16:37

How to round with negative precision?

There is a task in which it is required to write the round() function. There is an indication in the problem: "Notice that the precision can be negative, which means that the part before the decimal dot will be rounded".
Can you explain how rounding with negative precision works?
There is an example in the task: "my_round(123, -1) must return 120". And if the accuracy is -2, then what should be returned?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wataru, 2021-07-14
@freecam

my_round(123,-2) = 100.
Precision says that all digits after this index must be 0. And the previous one may increase by 1, depending on the rounding rules.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question