Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Percentage oddity #53

Open
sergeevabc opened this issue Jul 2, 2021 · 4 comments
Open

Percentage oddity #53

sergeevabc opened this issue Jul 2, 2021 · 4 comments

Comments

@sergeevabc
Copy link

$ kalker.exe -10.5%+10.5%
-0.116025

Great, but it does not make sense. Qalc, for example, outputs 0 in this case.

@wischi-chr
Copy link

wischi-chr commented Sep 9, 2022

It's not really odd, it depends on how you interpret the input.

Percent is just a fancy way of writing scaled factors. So 50% just means 0.5, 10% is 0.1, etc.
One way of interpreting your calculation would be to expand the percent values to -0.105 + 0.105 which would be 0 (I guess that was how Qalc interpreted the calculation)

But that's not the only way a calculator can interpret the percent sign. For convenience calculators support "adding/subtracting" percentages which are technically multiplications and divisions.

Let's take for example 100 + 10% if we interpret it like before that would be 100 + 0.1 = 100.1. But that is clearly not the result the user expected. So "adding percentages" are really multiplications and 100 + 10% will be interpreted as 100 * 1.1 which is 110. You can see this in action if you change the order in Qcal. Addition in general is commutative but "percentage addition" is not because the "+ 10%" is multiplied to the value that came before ... if there is no value before you don't have a base value and it will be reinterpreted just as a number/100 so 10% will become 0.1.

Qcal:

100 + 10% -> 110
10% + 100 -> 100.1

this is also what happens in kalker with your calculation -10.5% cannot be applied to anything that stands before it because it's the first expression, so it's evaluated to -0.105 now the next part +10.5% is applied to the value left of it. Remember "percentage add" is a multiplication so -0.105+10.5% is evaluated (also in Qcal) as -0.105*1.105 which is -0.116025

So neither Qalc nor kalker are "right" or "wrong" here, it's basically an edge case because percentages can be interpreted in two different ways and it's not always clear what the user meant (it's ambiguous).

My tip: only do very basic stuff if you use the percentage operator. If you need to do advanced stuff be more explicit and don't use the percent sign in you calculations.

@aukeroorda
Copy link

Just leaving my thoughts - the approach of using a percentage suffix to write fractions is okay-ish, but having their value based on the preceding numeric value is such a strange approach. Of course it matches with the natural language description of these calculations, but the conversion to a proper computation of the value should be done by the users of this program, and not as an ambiguous (modulo or percentage operation?) implicit conversation step in this program, especially if you target a scientific audience. It feels out of place in this otherwise well designed program.

@timokoesters
Copy link
Contributor

I agree, percentage for me is just a shorthand for 1/100. But maybe there should be a flag to toggle the behavior, if it is a common convention for others.

@PaddiM8
Copy link
Owner

PaddiM8 commented Mar 31, 2024

It's quite common for calculators to base the result on the preceding value (WolframAlpha does it too) and I use it quite a lot myself for quick calculations, to do things like 130 - 25%, but yes it can lead to confusion. Having a flag to disable it would probably be reasonable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants