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

When formatting zero or a negative number as bytes, the original number is returned #222

Open
rgravina opened this issue Nov 13, 2014 · 1 comment

Comments

@rgravina
Copy link

I noticed that when bytes is zero or negative, the original number is returned, instead of a formatted number.

// positive values are OK
numeral(1024).format('0.0b')
"1.0KB"

// zero and negative values return unchanged
numeral(0).format('0.0b')
"0.0"
numeral(-1024).format('0.0b')
"-1024.0"

Since none of the documentation examples show negative bytes, I wonder if this is intentional?

A workaround for negative values is to do this in client code using the library:

// if the value is negative, before displaying....
'-'+numeral(Math.abs(-1024)).format('0.0b')
"-1.0KB"

If the value is zero however, I think some other fix is required.

@rgravina rgravina changed the title When formatting a negative number as bytes, the original number is returned When formatting zero or a negative number as bytes, the original number is returned Nov 13, 2014
@therebelrobot
Copy link

Can confirm in my own code that numeral(0).format('0b') is being returned without the unit.

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