Math function step

I need a function that returns:

  • for any number from the range => the result

    [0.001,0.01) => 0.01

    [0.01,0.1) => 0.1

    [0.1,1) => 1

    [1,10) => 10

    [10,100) => 100

    and etc.

My first idea was to use if, but this is the worst way. Is there a simple solution?

+3
source share
1 answer
10^(floor(log(x) + 1))
+6
source

Source: https://habr.com/ru/post/1747075/


All Articles