how to round down and round up the decimal vlaues in pytho.
user input
a =2.336 After round up it should be like a =2.34
a =4.13623 After round up it should be like a =4.14
Is there any built in functions in python to manipulate
how to round down and round up the decimal vlaues in pytho.
user input
a =2.336 After round up it should be like a =2.34
a =4.13623 After round up it should be like a =4.14
Is there any built in functions in python to manipulate
you could try something like
a = 2.336
a = math.ceil(a*pow(10,2))/pow(10,2)
here 2
in pow(10,2)
stands for the precision you need behind the decimal point
You can use the ceil()
and floor()
functions from the math module. Here's some code to help you get started.
def round_up(n, decimals=0):
multiplier = 10 ** decimals
return math.ceil(n * multiplier) / multiplier
Try figuring out how the decimal and multiplier variables are working here.