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
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?
Similar Posts
- Get Key from a Dictionary using Value in Python
- Get a value from DataFrame row using index and column name in pandas
- Get last item or value from a List in python
- Get the largest value from a List in Python
- Get highest id or value record from a column SqlAlchemy Query
- [Python] Default value of function argument
- Delete a key value pair from a dictionary in Python