Skip to content

Return empty string for Infinity and properly format values such as 0.999 #720

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

Merged
merged 2 commits into from
Feb 21, 2015
Merged

Return empty string for Infinity and properly format values such as 0.999 #720

merged 2 commits into from
Feb 21, 2015

Conversation

44px
Copy link

@44px 44px commented Feb 21, 2015

This PR fixes two issues in currency filter (demo for both: http://jsfiddle.net/k5bv3r62/ ):

  1. x.999 values are shown as $x.00
    Say you have model with value 0.999. With currency filter applied it will be shown as $0.00

  2. Infinity value show as $In,finity.ty
    I think, it would be good to return empty string as for falsy values

Also I added new test cases for described issues.

@yyx990803
Copy link
Member

Thanks for the PR. Would it be weird to have Infinity output as empty string though? Maybe it should just print "Infinity"?

@44px
Copy link
Author

44px commented Feb 21, 2015

Thanks for response.

That's interesting question. Here is my thoughts:
It seems that printing an empty string is a default way to say that value is wrong. Currency filter does it for undefined and for NaN. And it would be less weird to see 'Amount: ' than 'Amount: NaN' or 'Amount: Infinity' somewhere in interface.

Also I made this test with AngularJS, it prints empty string: http://jsfiddle.net/41Lga6bg/

sign = sign || '$'
var s = Math.floor(Math.abs(value)).toString(),
i = s.length % 3,
h = i > 0
? (s.slice(0, i) + (s.length > 3 ? ',' : ''))
: '',
f = '.' + value.toFixed(2).slice(-2)
v = Math.abs(parseInt((value * 100) % 100, 10)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix indent here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@yyx990803
Copy link
Member

Sounds good, it's probably a good idea to keep the filter consistent with Angular's implementation.

yyx990803 added a commit that referenced this pull request Feb 21, 2015
Return empty string for Infinity and properly format values such as 0.999
@yyx990803 yyx990803 merged commit 67759d2 into vuejs:dev Feb 21, 2015
@yyx990803
Copy link
Member

Thanks!

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

Successfully merging this pull request may close these issues.

2 participants