I found:

IDLE 1.2.2
>>> x = 157.73
>>> r = x * 100.
>>> int(r)
15772

Can I convert more precise?

Recommended Answers

All 3 Replies

>>> int(round(r)) 15773

The way floating point numbers are represented in many computer languages leads to roundoff errors. Take a look at this ...

q = [157.73 * 100.0]
print q                    # [15772.999999999998]
# this explains why
print int(157.73 * 100.0)  # gives 15772

For really high precision math that prepresents floating point numbers differently use the Python module decimal.

thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.