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 calculations #8

Open
lehnen opened this issue Feb 27, 2018 · 2 comments
Open

Percentage calculations #8

lehnen opened this issue Feb 27, 2018 · 2 comments

Comments

@lehnen
Copy link

lehnen commented Feb 27, 2018

Hy Chris,

I try to implement a percentage calculation in form of:
20 + 19% that should result in 23.8 or
45 * 10% that should result in 202.5
For the first one you could also state 20 * 1.19, but the users are more familiar to the first way.

As I can see, the calculator can be extended, but operators always follow the form x [operator] y.

Do you see a way how I can implement this with the AbstractSymbol API?

Greetings from Germany
Volker

@chriskonnertz
Copy link
Owner

chriskonnertz commented Feb 28, 2018

Hello,

I try to implement a percentage calculation in form of: 20 + 19% that should result in 23.8

well, good luck. 😉

20 + 19% is the same as (20 + 19%) wich is the same as (20 * 1.19)

Okay, let's ignore the brackets for know, so we assume 20 + 19% is exactly the same as 20 * 1.19.
So we could say that the + operator is transformed into *.
Unfortunately, in the current implementation operators always operate on numbers.
How could the plus operator (class) decide when it has to do a conventional addition and when to do a multiplication instead? Right know I do not have an answer.
But this is just straight forward thinking, maybe there are other ways.

45 * 10% that should result in 202.5

I guess that should be possible when allowing unary operators to be in postfix notation.
I need some time to figure out how to do that (haven't spent much time with StringCalc lately).

@lehnen
Copy link
Author

lehnen commented Mar 5, 2018

Thx a lot. Would be great.
I will try some ideas also.

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

No branches or pull requests

2 participants