-2

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.

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

FLAK-ZOSO
  • 3,873
  • 4
  • 8
  • 28
user3098629
  • 175
  • 1
  • 1
  • 13
  • 5
    Pay attention to the `e-06` part. That's scientific notation, used by default for sufficiently large or small values - see https://stackoverflow.com/a/25099656/2337736 for some options to change the formatting. – Peter DeGlopper Jun 03 '22 at 19:02
  • Why is it not correct? Do you understand what `e-06` means? – PM 77-1 Jun 03 '22 at 19:02
  • Please see https://en.wikipedia.org/wiki/Scientific_notation. – Karl Knechtel Jun 03 '22 at 19:06
  • 2
    This should really have just been duped to [Convert Scientific Notation to Float](https://stackoverflow.com/q/25099626/364696). – ShadowRanger Jun 03 '22 at 19:09
  • I agree with @MichaelSzczesny, is this the real reason? Because it sounds strange to me... this is not a typo at all. – FLAK-ZOSO Jun 03 '22 at 19:09
  • 2
    @MichaelSzczesny: Sometimes people stretch "not reproducible" to mean "the code is actually behaving correctly, the OP just doesn't realize it". In the sense that there is no problem to reproduce. Not endorsing it here (this should have just been duped to one of a few similar questions asked here), but people do it. – ShadowRanger Jun 03 '22 at 19:11
  • @ShadowRanger, should we make a post on MetaStackOverflow about it? This close reason should be added because it happens often. – FLAK-ZOSO Jun 03 '22 at 19:13
  • 1
    @FLAK-ZOSO: You're welcome to. I've largely avoided Meta so far. – ShadowRanger Jun 03 '22 at 19:16
  • I'd still give OP props for providing enough code for a clear reproduction and explanation of why they thought it was incorrect (even though they were mistaken). – Kenny Ostrom Jun 03 '22 at 19:22
  • @ShadowRanger I've largely avoided Meta too, but I made this [feature-request] post about what we were discussing: https://meta.stackoverflow.com/questions/418514/adding-correct-behavior-minsuderstood-to-close-reasons – FLAK-ZOSO Jun 03 '22 at 19:25
  • @FLAK-ZOSO Did you delete the Meta post? – CrazyChucky Jun 03 '22 at 20:09
  • @CrazyChucky Yes, I thought I needed to since there were 3 downvotes, but I've just undeleted it in case somebody thinks the new close reason is needed. – FLAK-ZOSO Jun 03 '22 at 20:11

1 Answers1

1
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.

Zoe
  • 27,060
  • 21
  • 118
  • 148
FLAK-ZOSO
  • 3,873
  • 4
  • 8
  • 28