Skip to content

Support the unary postfix percentage operator (%) #279

Description

@ggyuchive

Description:

The formula parser does not recognise % as a unary postfix operator. In Excel and Google Sheets, =4% evaluates to 0.04 (the operator divides the operand by 100, and has higher precedence than the binary arithmetic operators). Wafflebase currently treats % as either an unknown token or a binary operator, so common idioms like =A1 * 5% or =B2 + 10% cannot be expressed.

What you expected to happen:

  • =4% parses and evaluates to 0.04.
  • =4% * 3 parses and evaluates to 0.12 (because % binds tighter than *).
  • =5% + 10% evaluates to 0.15.
  • =A1 * 5% works for any numeric A1.
  • =4%3 raises a syntax error — 4% is a complete expression, and 3 cannot follow without a binary operator. This matches Google Sheets.

How to reproduce it (as minimally and precisely as possible):

Setup: A1=200.

Cell Formula Expected Actual Status
B1 =4% 0.04 #ERROR!
B2 =4% * 3 0.12 #ERROR!
B3 =5% + 10% 0.15 #ERROR!
B4 =A1 * 5% 10 #ERROR!
B5 =4%3 #ERROR! #ERROR! ✓ (should also error — but for the right reason)

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestgood first issueGood for newcomerssheetsRelated to wafflebase sheets component

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions