mango orange
mango orange

Reputation: 108

Why am I unable to show the precision of a float value using quantiphy and engfmt?

I'm working on an engineering calculator in python and I found some packages that can convert a float value to engineering notation. First I installed engfmt:

Code:

from engfmt import to_eng_fmt

num = -327.2051
num = to_eng_fmt(num, prec=4)
print(num)

Output:

-327.21

The second package that I installed is quantiphy because it is a new release and serves the same purpose as the engfmt :

Code:

from quantiphy import Quantity

num = -327.2051
num = Quantity(num).fixed(prec=4)
print(num)

Output:

-327.21

What I want is to show the precision decimal value upto 4 places. like this -327.2051

Version:

Upvotes: 2

Views: 80

Answers (1)

MarianD
MarianD

Reputation: 14201

In both cases the keyword argument prec= doesn't specify the number of digits after the decimal point. It determines the precision of the whole number, i.e. the number of all digits.

By convention the number of all digits is a specified precision plus 1, i.e. your precision prec=4 gives a 5-digit result.

Increase your precision to prec=6 (in your case).

Upvotes: 3

Related Questions