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
Adding percentage of previous value #304
Comments
Having support for percentages would be nice. It's a bit tricky though, as the Maybe we could create percentage as a unit, so you could do something like |
I did not think of modulus. Your solution would work, I would only have to regex replace any |
There may be a way to support |
👍 |
|
You're right, it's not really doable, will give ambiguities in the expression parser which will lead to nasty situations. I will close this issue now, feel free to reopen if anyone has a brilliant idea for a solution :) |
I know this is an old topic but I wanted to share what I came up with for my application regarding percentages. If you use math.eval for your calculations as I do, this works pretty well. I am sure it's not perfect but check it out: It treats I hope to see handling of percentages in Math.js one day! |
Thanks for sharing your solution @bornova! |
@bornova awesome solution. |
I was wondering if this feature can be easily added to this already great library. I often have to add a percentage to a value, the strings are usually stored in a database and would look something like this:
"(value)+25%"
When the operation is not using percents, I replace the "(value)" with the value I need and eval it. But I can't use the "+25%" part, I have to change it to
"(value)*1.25"
I can then change the "(value)" to the needed value and then run the math.eval() function. The big problem with this approach is that is that is does not always respect the operation order, for example "3+5+10%" should equal 8.8, but "3+5*1.1" equal 8.5.
Also, since I'm not always the one entering those formulas in the database, I can't change the formulas. I was hoping this functionality can be added to the mathjs library. I started to look at the uncompressed code but though it might be easier just to ask you.
The text was updated successfully, but these errors were encountered: