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

intcomma rounding #198

Open
palewire opened this issue Jul 2, 2020 · 1 comment
Open

intcomma rounding #198

palewire opened this issue Jul 2, 2020 · 1 comment
Milestone

Comments

@palewire
Copy link

palewire commented Jul 2, 2020

I don't know if I would call this a feature or a bug or really anything more than just a thing, but I've noticed that intcomma decides to round off decimals of zero, but not other numbers. For instance:

journalize.intcomma(1000.0)
'1,000'

This is the case even when the user submits a value with an explicitly fixed decimal place.

journalize.intcomma((1000.0).toFixed(1))
'1,000'

I'm certain there is probably some good reason for this I'm unaware of, but I wanted to file this ticket since the second example above was not the behavior I expected as a user.

For what it's worth, it is also not the behavior of the old gods of Django.

>>> from django.contrib.humanize.templatetags.humanize import intcomma
>>> intcomma(1000.0)
'1000.0'
@rdmurphy
Copy link
Owner

rdmurphy commented Jul 2, 2020

Huh! I think that's a legitimate bug. The issue crops up because the very first thing intcomma does is coerce the input to a number:

const convertedVal = +val;

So if it comes over as a string ("1000.0") it's gonna get pulled off. But this may really be a legitimate difference between how Python and JavaScript works. In Python declaring a value as 1000.0 will respect the trailing 0, but JavaScript will not.

Python

val = 1000.0
print(val)
# 1000.0

JavaScript

const val = 1000.0;
console.log(val);
// 1000

So I think the question is should intcomma respect and mirror what comes after a decimal with a string input, and is there anything to be done for number inputs?

@rdmurphy rdmurphy added this to the v3 milestone Jan 6, 2023
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