Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

### Fixed

- Fixed parsing of consecutive percent operators, such as `=5%%`. [#1773](https://github.com/handsontable/hyperformula/pull/1773)
- Fixed the `AVERAGEIF` function returning a division-by-zero error when the calculated average was `0`. [#1733](https://github.com/handsontable/hyperformula/pull/1733)
- Fixed the localized names of `VSTACK` and `HSTACK` in 14 language packs to match Microsoft Excel. [#1748](https://github.com/handsontable/hyperformula/pull/1748)
- Fixed the MAXPOOL and MEDIANPOOL functions throwing an uncaught `TypeError` instead of returning the `#VALUE!` error when the range dimensions are not a whole multiple of the window size and the stride. [#1718](https://github.com/handsontable/hyperformula/pull/1718)
Expand Down
6 changes: 5 additions & 1 deletion docs/guide/types-of-operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ returns the negative value of that number.
| :--- | :--- | :--- | :--- |
| - | Unary minus | -a | Returns the negative of its argument. |
| + | Unary plus | +a | Returns the positive of its argument. |
| % | Percent | a% | Calculate the percent of an argument. |
| % | Percent | a% | Divides its argument by 100. |

HyperFormula supports consecutive percent operators. Each `%` divides the
preceding result by `100`. For example, `=5%%` is equivalent to `=(5%)%`
and returns `0.0005`, while `=5%%%` returns `0.000005`.

## Binary arithmetic operators

Expand Down
18 changes: 9 additions & 9 deletions src/parser/FormulaParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,18 +561,18 @@ export class FormulaParser extends EmbeddedActionsParser {
])) as Ast
})

/**
* Rule for atomic expressions followed by zero or more percent operators.
*/
private rightUnaryOpAtomicExpression: AstRule = this.RULE('rightUnaryOpAtomicExpression', () => {
const positiveAtomicExpression = this.SUBRULE(this.positiveAtomicExpression)

const percentage = this.OPTION(() => {
return this.CONSUME(PercentOp)
}) as Maybe<ExtendedToken>
let expression: Ast = this.SUBRULE(this.positiveAtomicExpression)

if (percentage) {
return buildPercentOpAst(positiveAtomicExpression, percentage.leadingWhitespace)
}
this.MANY(() => {
const percentage = this.CONSUME(PercentOp) as ExtendedToken
expression = buildPercentOpAst(expression, percentage.leadingWhitespace)
})

return positiveAtomicExpression
return expression
})

/**
Expand Down
Loading