Skip to content

Ecma-402 proposal for selecting different rounding functions for Intl.NumberFormat

Notifications You must be signed in to change notification settings

rxaviers/ecma402-number-format-round-option

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 

Repository files navigation

NumberFormat round option

Proposal for stage 0

Allows to select a rounding function for NumberFormat different than round "half-even". For example: ceil, floor, or truncate.

Such option is present on Unicode Technical Standard #35, part 3 Numbers, which says "An implementation may allow the specification of a rounding mode to determine how values are rounded".

http://www.unicode.org/reports/tr35/tr35-numbers.html#Rounding

Usage

let formatUsingHalfEvenRounding = new Intl.NumberFormat("en").format(Math.PI);
// "3.142"

let formatUsingFloorRounding = new Intl.NumberFormat("en", {round: Math.floor}).format(Math.PI);
// "3.141"

let formatCurrencyUsingCeilRounding = new Intl.NumberFormat("en", {
  style: "currency",
  currency: "USD",
  currencyDisplay: "symbol",
  round: Math.ceil
}).format(9.991);
// "$10.00"

About

Ecma-402 proposal for selecting different rounding functions for Intl.NumberFormat

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published