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 a number without trailing zeros. #176

Closed
tmcconechy opened this issue Sep 10, 2013 · 1 comment
Closed

Format a number without trailing zeros. #176

tmcconechy opened this issue Sep 10, 2013 · 1 comment

Comments

@tmcconechy
Copy link

Is there a way to call .format() and not have it append trailing zeros i'm not seeing?

Globalize.format( 123.45, "n3" ) -> 123.450

I would like it to return 1234.45. The real issue is how ugly the formatting can be on larger numbers like n9.

Globalize.format( 123.45, "n9" ) -> 123.4500000000
Globalize.format( 123.123456, "n9" ) -> 123.123456000

@rxaviers
Copy link
Member

rxaviers commented Jun 3, 2014

Now (1.x), you can:

> Globalize.formatNumber(123.45, {maximumFractionDigits: 5})
'123.45'
> Globalize.formatNumber(123.456789, {maximumFractionDigits: 5})
'123.45679'

The 0-padded analogue is:

> Globalize.formatNumber(123.45, {minimumFractionDigits: 5, maximumFractionDigits: 5})
'123.45000'
> Globalize.formatNumber(123.456789, {minimumFractionDigits: 5, maximumFractionDigits: 5})
'123.45679'

I would like it to return 1234.45. The real issue is how ugly the formatting can be on larger numbers like n9.

If you need your fraction to be capped at 2 digits, use maximumFractionDigits: 2.

For more info, read https://github.com/jquery/globalize/blob/master/doc/api/number/format.md.

@rxaviers rxaviers closed this as completed Jun 3, 2014
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