Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format string for rounding to nearest integer #745

Open
eradman opened this issue Nov 13, 2023 · 1 comment
Open

Format string for rounding to nearest integer #745

eradman opened this issue Nov 13, 2023 · 1 comment

Comments

@eradman
Copy link

eradman commented Nov 13, 2023

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?

eradman pushed a commit to eradman/redash that referenced this issue Nov 14, 2023
This reverts commit f8934b8.

Using a format string of '0' does not round to the nearest integer in Numbro
BenjaminVanRyseghem/numbro#745
guidopetri added a commit to getredash/redash that referenced this issue Nov 25, 2023
This reverts commit f8934b8.

Using a format string of '0' does not round to the nearest integer in Numbro
BenjaminVanRyseghem/numbro#745

Co-authored-by: github-actions <github-actions@github.com>
Co-authored-by: Guido Petri <18634426+guidopetri@users.noreply.github.com>
@vitaliy-kretsul
Copy link

vitaliy-kretsul commented Dec 23, 2023

Looks like I bumped into the same issue:

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

The expected output is '99%'

harveyrendell pushed a commit to pushpay/redash that referenced this issue Jan 8, 2025
This reverts commit f8934b8.

Using a format string of '0' does not round to the nearest integer in Numbro
BenjaminVanRyseghem/numbro#745

Co-authored-by: github-actions <github-actions@github.com>
Co-authored-by: Guido Petri <18634426+guidopetri@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants