python round without math 1

python round without math

(int(10*x-0.5)+1) / 10.0

Here is what the above code is Doing:
1. We’re using the map function to apply the round_to_1 function to every element in the list.
2. The round_to_1 function takes a number x and returns another number that is rounded to 1 decimal place.
3. We use 10*x because this will move the decimal place over one place to the right.
4. We then use the floor function to round down to the nearest whole number.
5. Finally, we move the decimal place back one position to the left.

Similar Posts