Spatial Digger
Spatial Digger

Reputation: 1993

double to float without rounding python

say a = 580991.3636

When I b = np.float32(a)

b 580991.4

I'm after b 580991.3636

I'm hoping this is an easy one, any ideas? I'm also assuming it is my misunderstanding of floats causing this. I know python is dynamic when it comes to dtypes, but I need it to be in float32 for a specific library (python-pcl).

Upvotes: 0

Views: 182

Answers (1)

user9849588
user9849588

Reputation: 607

Float32 can only offer between 6 and 9 digits of precision.

Float32 works by storing the sign in 1 bit, the exponent in 8 bits and the value in 23 bits (also called the fraction). So you can represent a wide range of real numbers at the cost of precision.

If you need it to be more precise it has to be a double or use the python's library decimal.

Upvotes: 3

Related Questions