How can I format a float so that it doesn\'t contain trailing zeros? In other words, I want the resulting string to be as short as possible.
For example:
<
Here's the answer:
import numpy num1 = 3.1400 num2 = 3.000 numpy.format_float_positional(num1, 3, trim='-') numpy.format_float_positional(num2, 3, trim='-')
output "3.14" and "3"
trim='-' removes both the trailing zero's, and the decimal.
trim='-'