x = 0.2
y= 12
z= x/y #0.0166666666667
On using round(z,2) i get 0.02 , where i need the system to take only 0.01.
x = 0.2
y= 12
z= x/y #0.0166666666667
On using round(z,2) i get 0.02 , where i need the system to take only 0.01.
The only way I can think of would be multiplying by 100, using the math.floor()
function, then dividing by 100. I don't like it at all, though.
z = (math.floor(100*(x/y)))/100
If you'd like to avoid casting to str
and slicing, you can cast to Decimal
and use quantize
from decimal import Decimal, ROUND_DOWN
x = 0.2
y = 12
z = Decimal(x/y).quantize(Decimal('1.00'), rounding=ROUND_DOWN)
Although I think I know what you wanna do, that logic is not right in mathematics. In math you either round up or down-- which is why python gave you 0.02.
My guess is you just want the whole number part and a number of decimal places after. Try this then:
def cut_down(number, dec_plc):// needs a decimal and number of decimal places.
z_str= str(number)
z_str= z_str[:dec_plc+3] places
return float(z_str)
if you want to show only 0.01 out of 0.016666667, you can use
>>> str(z)[0:4]
>>> '0.01'