python - How can I correct this rounding down function? -


how can correct rounding down function?

def round_down(num, prec):     uod = round(num, prec)     if uod > num:         return uod - 1/10^prec       return uod 

it raises: typeerror: unsupported operand type(s) ^: 'float' , 'int'.

^ not mean think means. use ** instead.

from python documentation:

the ^ operator yields bitwise xor (exclusive or) of arguments, must plain or long integers.

also, mgilson noted, 1/10 equal 0 in python 2.x, want use 1.0/10 instead:

def round_down(num, prec):     uod = round(num, prec)     if uod > num:         return uod - 1.0/10 ** prec       return uod 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -