Suresh Subedi
Suresh Subedi

Reputation: 720

Why python returns 0 when rounding a floating point number?

I am trying to round a floating point number but it returns zero. Why is that? How can I round my floating point number to 3 digits after decimal?

>>> a= 9.907283855185141e-32
>>> round(a,3)
0.0
>>> type(a)
<class 'float'>

Upvotes: 1

Views: 1314

Answers (1)

Yu Hao
Yu Hao

Reputation: 122493

The number a, if written in decimal, is

0.00000000000000000000000000000009907283855185141

If rounded to 3 digits after the decimal, it is in fact 0.

Upvotes: 4

Related Questions