In Python, we can tackle the precision of floating-point numbers by the use of different functions. Most of these functions are present in the “math” module. Let us look into some of the frequently used operations in Python for Data Science.
- trunc(): It eliminates all the decimal places and returns integer without any decimal points.
- ceil(): It gives the least integer greater than the number provided.
- floor(): It is the opposite of ceil() and gives the greatest integer smaller than the integer provided.
Setting the Precision:
- Using (%): It is denoted by “%”. It is used for setting precision and for formatting.
- Using format(): This is another method of formatting the string for setting precision.
- Using round(x, n): Here we have to provide two arguments, one is the number and the other is the number till which we want the decimal value to be rounded off.