Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Latest commit

 

History

History
148 lines (138 loc) · 4.33 KB

File metadata and controls

148 lines (138 loc) · 4.33 KB

<-- Go back to README.md

Round

Rounds the provided number based on the provided precision and/or rounding behaviour.

Placeholder patterns

  • %formatter_number_round_<number>%
  • %formatter_number_round_[precision]:[rounding_mode]_<number>%

Options

Option Description

precision

How many digits after the decimal point should be kept.
Type: Number
Required? No
Conditions:
  • 0 ≤ x
Default: Config value (expansion.formatter.rounding.precision)

rounding_mode

How the number should be rounded if any fractions are discarded.

⚠️ See below for available rounding modes. ⚠️
Type: String
Required? No
Default: Config value (expansion.formatter.rounding.mode)

number

The number to convert.
Type: Number
Required? Yes

Rounding modes

  • up
    • Rounds away from zero. Always increases the digit prior to a non-zero discarded fraction.
    • Examples:
      • -1.5 -> -2
      • -1.1 -> -2
      • -1.0 -> -1
      • 1.0 -> 1
      • 1.1 -> 2
      • 1.5 -> 2
  • down
    • Rounds towards zero. Always decreases the digit prior to a non-zero discarded fraction.
    • Examples:
      • -1.5 -> -1
      • -1.1 -> -1
      • -1.0 -> -1
      • 1.0 -> 1
      • 1.1 -> 1
      • 1.5 -> 1
  • ceiling
    • Rounds towards positive infinity. Always rounds up if number is positive, otherwise rounds down.
    • Examples:
      • -1.5 -> -1
      • -1.1 -> -1
      • -1.0 -> -1
      • 1.0 -> 1
      • 1.1 -> 2
      • 1.5 -> 2
  • floor
    • Rounds towards negative infinity. Always rounds down if number is positive, otherwise rounds up.
    • Examples:
      • -1.5 -> -2
      • -1.1 -> -2
      • -1.0 -> -1
      • 1.0 -> 1
      • 1.1 -> 1
      • 1.5 -> 1
  • half-up
    • Rounds to nearest neighbour unless both neighbours are equidistant (5) in which case round up. This is what you are usually taught in school.
    • Examples:
      • -1.5 -> -2
      • -1.1 -> -1
      • -1.0 -> -1
      • 1.0 -> 1
      • 1.1 -> 1
      • 1.5 -> 2
  • half-down
    • Rounds to nearest neighbour unless both neighbours are equidistant (5) in which case round down.
    • Examples:
      • -1.5 -> -1
      • -1.1 -> -1
      • -1.0 -> -1
      • 1.0 -> 1
      • 1.1 -> 1
      • 1.5 -> 1
  • half-even
    • Rounds to nearest neighbour unless both neighbours are equidistant (5), in which case, round to nearest even neighbour (Up if digit to the left is odd, otherwise down)
    • Examples:
      • -1.5 -> -2
      • -1.1 -> -1
      • -1.0 -> -1
      • 1.0 -> 1
      • 1.1 -> 1
      • 1.5 -> 2

Examples

/papi parse me %formatter_number_round_1.5%             -> 2     # Default is half-up
/papi parse me %formatter_number_round_3:_1.5%          -> 2.000 # Default is half-up
/papi parse me %formatter_number_round_:half-down_1.5%  -> 1
/papi parse me %formatter_number_round_3:half-down_1.5% -> 1.000