BenjaminVanRyseghem / numbro

A JS library for number formatting
http://numbrojs.com
MIT License
1.09k stars 197 forks source link

Format string for rounding to nearest integer #745

Open eradman opened 8 months ago

eradman commented 8 months ago

version: numbro 2.4.0

After transitioning from numeral.js I noticed that a format string of '0' does not round to the nearest integer

> var numbro = require("numbro");
undefined
> num = numbro(23.4333333);
R { _value: 23.4333333 }
> num.format('0')
'23.4333333'

Adding one or more decimal places does round to the specified number of digits

> num.format('0.0')
'23.4'
> num.format('0.00')
'23.43'

Is there an alternate syntax for displaying a number with no decimal places?

vitaliy-kretsul commented 6 months ago

Looks like I bumped into the same issue:

> numbro(0.99123).format('0%')
'99.123%'

The expected output is '99%'