Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

When using rounding numbers that are negative and round to 0 show a negative sign #8489

Closed
jrgleason opened this issue Aug 5, 2014 · 9 comments

Comments

@jrgleason
Copy link

We ran into this while rounding to one decimal

http://plnkr.co/edit/cUqjvRuBnSfcrAC7Visz?p=preview

Basically if I were to have a value like -.01 and I would use number:1 then it shows -0.0 which would seem to be invalid.

@jrgleason
Copy link
Author

Now that I am looking at it seems there is a problem with Math.round and fractions in general with JS.

@jrgleason
Copy link
Author

I changed my code to this and it seems to be working maybe we can use that in the code?

@petebacondarwin
Copy link
Member

Do you think you could provide a pull request for this?

@petebacondarwin petebacondarwin added this to the Backlog milestone Aug 6, 2014
@btford btford removed the gh: issue label Aug 20, 2014
@smilli
Copy link
Contributor

smilli commented Aug 23, 2014

I created a patch for this, but it seems like this is actually expected behavior? Or at least according to this test

@jrgleason
Copy link
Author

Huh that makes little sense to me
On Aug 23, 2014 1:24 AM, "Smitha Milli" notifications@github.com wrote:

I created a patch for this, but it seems like this is actually expected
behavior? Or at least according to this test

expect(number(-1e-50, 0)).toEqual('-0');


Reply to this email directly or view it on GitHub
#8489 (comment).

@jrgleason
Copy link
Author

I mean I get it is supposed to signify the original number was negative but
I thought when rounding it became that number and there is no negative 0.
Unless I am missing some complicated math rule
On Aug 23, 2014 9:24 AM, jackiegleason@gmail.com wrote:

Huh that makes little sense to me
On Aug 23, 2014 1:24 AM, "Smitha Milli" notifications@github.com wrote:

I created a patch for this, but it seems like this is actually expected
behavior? Or at least according to this test

expect(number(-1e-50, 0)).toEqual('-0');


Reply to this email directly or view it on GitHub
#8489 (comment)
.

@caitp
Copy link
Contributor

caitp commented Aug 23, 2014

in regular math, 0 has no sign --- but with IEEE 754 math, 0 does have a sign because that's just how the format works. But yeah we generally don't want to format it that way =P It should be a pretty small patch to write, why not have a go at it? -0 === +0 should evaluate to true, so you could instead say if (number === 0) number = 0; or something similar.

@jrgleason
Copy link
Author

Will do give me a bit to get tests and all setup. I will work on it tonight
On Aug 23, 2014 10:18 AM, "Caitlin Potter" notifications@github.com wrote:

in regular math, 0 has no sign --- but with IEEE 754 math, 0 does have a
sign because that's just how the format works. But yeah we generally don't
want to format it that way =P It should be a pretty small patch to write,
why not have a go at it? -0 === +0 should evaluate to true, so you could
instead say if (number === 0) number = 0; or something similar.


Reply to this email directly or view it on GitHub
#8489 (comment).

@smilli
Copy link
Contributor

smilli commented Aug 23, 2014

Actually, I already created a fix earlier, just updated that test case from above in #8745.

btford pushed a commit that referenced this issue Sep 3, 2014
Previously when a negative number was rounded to 0 by the number filter
it would be formated as a negative number.  This means something like
{{ -0.01 | number: 1 }} would output -0.0.  Now it will ouput 0.0
instead.

Closes #8489
@btford btford closed this as completed in ae952fb Sep 3, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants