Precision Handling:

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.

  1. trunc(): It eliminates all the decimal places and returns integer without any decimal points.
  2. ceil(): It gives the least integer greater than the number provided.
  3. floor(): It is the opposite of ceil() and gives the greatest integer smaller than the integer provided.

python for data science text

Setting the Precision:

  1. Using (%): It is denoted by “%”. It is used for setting precision and for formatting.
  2. Using format(): This is another method of formatting the string for setting precision.
  3. 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.

To learn more about precision in python for data science, you can check this and this as well.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.