Skip to main content
@usenarrator/plugin-decimal Money code often uses decimal.js to avoid floating point errors. Without help, a chain like new Decimal(a).times(b).plus(c) reads as a series of method calls. The decimal plugin reads it as arithmetic, and reads comparisons as comparisons, including their negations. This plugin is also the worked example in Writing a plugin.

Examples

Arithmetic chains read left to right
English
Comparisons and their negations
English
Without the plugin, the same comparison reads like this:
Without the plugin
English

What it covers

  • new Decimal(x) reads as x.
  • Arithmetic: plus and add, minus and sub, times and mul, div and dividedBy, toDecimalPlaces, toNumber. add is only claimed on a new Decimal(...) receiver, so set.add(x) is unaffected.
  • Conditions: lt, lte, gt, gte, eq, equals, isZero, isNegative, isPositive.

Translating

The English phrasebook is exported as decimalEn and typed as DecimalPhrases.