calculator icon indicating copy to clipboard operation
calculator copied to clipboard

Error in percentage calculation

Open EnriquePG-Noc opened this issue 3 years ago • 6 comments

What Happened?

When performing an addition or subtraction operation with percentages, the program ignores that it is a percentage. For example: 100 + 2% = 100.02 (the correct would be 102). 100 - 2% = 99.98 (correct would be 98)

This happens with any number you type.

Steps to Reproduce

  1. I opened the calculator from "Applications".
  2. I typed the numbers from the keyboard, including the symbols.
  3. I get the wrong result.
  4. I enter the values and symbols from the calculator program itself.
  5. I persist with the error.

Expected Behavior

Basically because it is expected to operate with percentages, but what it seems to perform is a decimal operation.

OS Version

6.x (Odin)

Software Version

Latest release (I have run all updates)

Log Output

No response

Hardware Info

No response

EnriquePG-Noc avatar Feb 02 '22 06:02 EnriquePG-Noc

There was a PR (#137) suggesting a way of dealing with this but it did not get any traction at the time.

jeremypw avatar Feb 03 '22 11:02 jeremypw

Without this function it's completely useless for me, Elementary you can remove it from the OS, I have to use another one.

Dragonfir3 avatar Oct 26 '23 11:10 Dragonfir3

Duplicate of #44. This is an old issue for which no universally acceptable solution was found due to the ambiguity of the % operator (which the project leaders would prefer to be ignored altogether).

jeremypw avatar Oct 26 '23 17:10 jeremypw

Looked at how Google handles this - essentially it does not interpret % as the mod operator. If you enter a % b then it interpolates x to give a% x b. If you enter a + b + c% it gives a + c% x b. It should be possible to emulate this behaviour. Calculator does not seem to implement mod anyway.

Correction, Calculator recognises mod as the modulo operator (but not %%)

jeremypw avatar Oct 26 '23 17:10 jeremypw

@EnriquePG-Noc, @Dragonfir3 I have pushed a PR to address this - #268. If you are able to build and test this I would welcome your comments.

jeremypw avatar Dec 03 '23 18:12 jeremypw