Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python multiplying decimals less than 1

I am trying to multiply two decimals but Python 3 does not seem to respect the fact the numbers are decimals.

The basic code I have is:

val1 = 0.00141643059490085
val2 = 0.00623423464234545
Res  = val1 * val2
print(str(Res))

The result I am getting is 8.830360683208854e-06 which obviously is not correct.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

It appears to be stripping the decimal and zeros and just multiplying the remaining number.

>Solution :

8.830360683208854e-06 

Do you know what does it mean? It’s just scientific notation.


You can read it as the following.

8.830360683208854 multiplied by 10 elevated to an exponent of -6


So the result of the sum is correct, but you may want to format the float in a different way, in this case I suggest to read this post.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading