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

ToQuantity does not support long quantities #503

Closed
pshrosbree opened this issue Dec 19, 2015 · 6 comments
Closed

ToQuantity does not support long quantities #503

pshrosbree opened this issue Dec 19, 2015 · 6 comments
Assignees
Milestone

Comments

@pshrosbree
Copy link

It would be useful if ToQuantity supported long quantities in addition to int. Something like the following would work but will not honor ShowQuantityAs.Words for large positive or negative quantity values:

public static string ToQuantity(this string input, long quantity, ShowQuantityAs showQuantityAs = ShowQuantityAs.Numeric, string format = null, IFormatProvider formatProvider = null)
{
    var str = quantity == 1 ? input.Singularize(false) : input.Pluralize(false);
    if (showQuantityAs == ShowQuantityAs.None)
        return str;
    if ((showQuantityAs == ShowQuantityAs.Numeric) || (quantity > int.MaxValue) || (quantity < int.MinValue))
        return string.Format(formatProvider, "{0} {1}", quantity.ToString(format, formatProvider), str);
    return string.Format("{0} {1}", ((int) quantity).ToWords(), str);
}
@hazzik
Copy link
Member

hazzik commented Dec 20, 2015

👍

@mexx
Copy link
Collaborator

mexx commented Dec 21, 2015

IMHO it's not really intuitive behavior.
Imagine

// int.MaxValue
"case".ToQuantity(2147483647, ShowQuantityAs.Words) =>
    "two billion one hundred and forty-seven million four hundred and eighty-three thousand six hundred and forty-seven cases"

// but int.MaxValue+1
"case".ToQuantity(2147483648, ShowQuantityAs.Words) =>
    "2147483648 cases"

I think, we should provide ToWords also for long.

@pshrosbree
Copy link
Author

I agree. What I pasted is a quick fix I was using at the time. My problem was that my types are usually long, and frequently larger than int.MaxValue, so casting does work. While ShowQuantityAs.Words is not as clear as ShowQuantityAs.Numeric, I agree it should be supported. I was not suggesting my code as the implementation.

@clairernovotny
Copy link
Member

Tagging as vNext unless this can be completed in the next couple of weeks.

@hazzik
Copy link
Member

hazzik commented Jan 2, 2016

@onovotny I don't think that we can fix this in a couple of weeks. To make it feature complete we need to complete a lot of languages.

@clairernovotny clairernovotny modified the milestones: v2.2, vNext Apr 18, 2017
@clairernovotny clairernovotny self-assigned this Apr 18, 2017
@clairernovotny
Copy link
Member

Merged in e88b07e. Additional langs can be added as they're available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants