-2

I need to round down when the decimal is different from a multiple of 0.10 For example

36.09- 36.00 /
36.10- 36.10/
36.17- 36.10/
36.33- 36.30/
36.66- 36.60/
36.82- 36.80/
36.98- 36.90

cents should be only( only accepted) 0.10 / 0.20 / 0.30 / 0.40 / 0.50 / 0.60/ 0.70 / 0.80 / 0.90

enter code here
lmiguelvargasf
  • 63,191
  • 45
  • 217
  • 228
Giancarlo
  • 21
  • 4
  • Welcome to SO. This isn't a discussion forum or tutorial. Please take the [tour] and take the time to read [ask] and the other links found on that page. Invest some time with [the Tutorial](https://docs.python.org/3/tutorial/index.html) practicing the examples. It will give you an idea of the tools Python offers to help you solve your problem. – wwii Sep 30 '19 at 16:25
  • Possible duplicate of [Rounding to two decimal places in Python 2.7?](https://stackoverflow.com/questions/17470883/rounding-to-two-decimal-places-in-python-2-7) – erncyp Sep 30 '19 at 16:31

3 Answers3

2

Try this. It works by using the python math library to floor the value.

# number is the amount of money (e.g. 36.66)
number = math.floor(number*10)/10
# number now becomes 36.60
Delkarix
  • 84
  • 11
0

you can't use round(x, 1) because it will round up, so you have to implement it yourself

def round_down(x):
     return int(x * 10) / 10
Kyle Safran
  • 463
  • 3
  • 8
0

Good afternoon everyone. Those of us in technology, the first thing we do is search on Google or research. generate ideas that can be specified in a solution. I initially thought, to separate the integer from the decimal and validate the decimal with the valid values ​​for me. I do not think the observations on: "did you look for them on the internet or did you do something?" Thank you all for your solutions and comments.

Giancarlo
  • 21
  • 4