Skip to content

Calculator: support percentages (200+15%, 200-15%, 200*15%) #4693

Description

@9i41

Is your feature request related to a problem? Please describe.

The Calculator plugin can't calculate percentages. Typing 200+15% or 200*15% shows no result, because % is the modulo operator in Mages. Percentages are one of the most common everyday calculations (discounts, taxes, tips), so I keep having to open another calculator for them.

Describe the solution you'd like

Treat % as a percent sign when no number follows it, the same way a handheld calculator does:

Input Result
15% 0.15
200*15% 30
200/50% 400
200+15% 230
200-15% 170
100-10%-10% 81

Modulo keeps working when a number follows %: 10%3 is still 1.

Describe alternatives you've considered

Writing 200*1.15 by hand works, but it is slower and less natural than 200+15%.

Additional context

I already have a working implementation with unit tests and will open a PR for it. Related: #4078 asked for % as modulo, and that behavior is kept.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions