probablykasper / cpc

Text calculator with support for units and conversion
https://crates.io/crates/cpc
MIT License
128 stars 14 forks source link

How to calculate percents correctly? #30

Closed sergeevabc closed 1 year ago

sergeevabc commented 1 year ago

qalc 90+10%=99, but cpc 90+10%=90.1

probablykasper commented 1 year ago

cpc doesn't treat addition of percentages as multiplication, so you'd have to do 90 * 110%.

Not sure whether it's a good idea, or what the implementation should be like, if this is implemented

Spotlight:
90 + 10%       = 90.1
90 + (5% + 5%) = 90.1

Google:
90 + 10%       = 99
90 + (5% + 5%) = 90.1

Raycast:
90 + 10%       = 99
90 + (5% + 5%) = 99

Google Calculator:
90 + 10%       = 99
90 + (5% + 5%) = 90.0525
sergeevabc commented 1 year ago

Since I'm coming from pre-Internet era, my reference devices are a hardware calculator by Citizen and a software one by Microsoft shipped with Windows OS. Both give me 99 in the first case (common scenario is to calculate price increase).

Thing is I need a lightweight portable CLI calculator, because it is faster to type such an expression than to point'n'click. Qalc is a good one, but it's not lightweight, alas.

As for x + (5% + 5%), not sure what it is.

probablykasper commented 1 year ago

It seems a bit tricky. How to treat

sergeevabc commented 10 months ago

Oh, cpc v.1.9.3 (September 2023) still produces results that are inconsistent with the rest of the world. Still 90.1 instead of 99. Aggrrhh.

probablykasper commented 10 months ago

I'd welcome a PR

It's not really possible to be consistent with the rest of the world when they're all inconsistent with each other (And Google isn't not even consistent with themselves). So I'm undecided on the best appoach.