python

Get tofixed of a value using round() Python

val = 12.89
val1 = round(val, 0)
val2 = round(val, 1)

print(val1)
print(val2)
# 13.0
# 12.9
Output
13.0
12.9

To get the round value from a float value you can use python inbuilt function round(). This function returns the rounding value of float value. This takes the value as a required parameter and second parameter as to which numbers you want to round it.

If you want to get the int value from this you can use below codmy

myVal = 15.79
int_val = int( round(myVal, 0) )
print(int_val)
# 16
Was this helpful?