Formatting floats

If you don't want to look at weird numbers with 16 decimal places, use the str() function to display the number as a string.

Warning You might be tempted to use the round() function to handle floating point numbers. But round() requires you to specify a precision (the number of digits to the right of the decimal point) and defaults to a precision of 0 (which removes all the digits to the right of the decimal point). This probably isn't what you want if you're working with decimal numbers!

Was this article helpful?

0 0

Post a comment