Skip to content

2.3.0: Add options.decimalsRounding to format()

Compare
Choose a tag to compare
@bpierre bpierre released this 06 Feb 18:00
· 58 commits to main since this release
76cfdfd

Allows to specify the rounding method used for the decimals.

// Using 4,569.988
const n = [456988n, 2] as const;

// With 1 digit
format(n, 1) // "4,569.9" (default rounding)
format(n, {  // "4,569.8" (rounding down)
  digits: 1,
  decimalsRounding: "ROUND_DOWN"
})

// With 2 digits
format(n, 2) // "4,569.88" (default rounding)
format(n, {  // "4,569.89" (rounding up)
  digits: 2,
  decimalsRounding: "ROUND_UP"
})