开发者

How to store exponential values using python

开发者 https://www.devze.com 2023-02-23 05:02 出处:网络
I am looking for a way to p开发者_如何学运维erform a digit divided by larger value(2/5000000) and then store that value in table, but the problem is when i save that value, only 0 is stored , instead

I am looking for a way to p开发者_如何学运维erform a digit divided by larger value(2/5000000) and then store that value in table, but the problem is when i save that value, only 0 is stored , instead of correct value.I tried with float, double precision, but still only 0 is stored, is there any other way .

Thank you


Remember to operate on floating numbers, and not convert it after the operation. E.g. 2/5000000.

Also, use the Decimal library, if you are looking for more accurate decimals.


You need to use floating point division. To be explicit, you can cast ints to float:

>>> a = 2
>>> b = 5000000
>>> c = a/float(b)
>>> c
4e-07

You can cast either a or b to float.

0

精彩评论

暂无评论...
验证码 换一张
取 消