-
Notifications
You must be signed in to change notification settings - Fork 966
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
Added string formatting options to ToQuantity #220
Conversation
readme probably needs updating as well? |
I like it. Good work :) Yes, we need to include this in the readme or no one's ever going to know about it. |
Done. Please proofread though. |
Thanks for adding the readme bit. There are three failing tests. Also your fork is quite a few commits behind the upstream. Please fix the tests and rebase your work. Thanks. |
|
||
```C# | ||
"dollar".ToQuantity(2, "C0", new CultureInfo("en-US")) => "$2 dollars" | ||
"dollar".ToQuantity(2, "C2", new CultureInfo("en-US")) => "$2.00 dollars" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is pretty cool. Thanks for the great addition.
Is it the tests I have added that are failing? |
Yes. Test 'Humanizer.Tests.ToQuantityTests.ToQuantityWordsWithCustomCultureFormatting(word: "case", quantity: 1234567, format: "N2", cultureCode: "de-CH", expected: "1 234 567,00 cases")' failed: Test 'Humanizer.Tests.ToQuantityTests.ToQuantityWordsWithCustomCultureFormatting(word: "case", quantity: 1234567, format: "N0", cultureCode: "de-CH", expected: "1 234 567 cases")' failed: Test 'Humanizer.Tests.ApiApprover.PublicApiApprovalTest.approve_public_api' failed: ApprovalTests.Core.Exceptions.ApprovalMismatchException : Failed Approval: Received file c:_mine\Code\Humanizer\src\Humanizer.Tests\ApiApprover\PublicApiApprovalTest.approve_public_api.received.txt does not match approved file c:_mine\Code\Humanizer\src\Humanizer.Tests\ApiApprover\PublicApiApprovalTest.approve_public_api.approved.txt. |
Just did a rebase. Can you by any chance run this piece of code on your machine and paste your output here? var number = 1234567;
number.ToString("N0", new CultureInfo("en-US")).ToList().ForEach(x => Console.Write((int)x + ":" + x + "-"));
number.ToString("N2", new CultureInfo("en-US")).ToList().ForEach(x => Console.Write((int)x + ":" + x + "-"));
number.ToString("N0", new CultureInfo("de-CH")).ToList().ForEach(x => Console.Write((int)x + ":" + x + "-"));
number.ToString("N2", new CultureInfo("de-CH")).ToList().ForEach(x => Console.Write((int)x + ":" + x + "-"));
|
Sure. Here it is: 49:1-44:,-50:2-51:3-52:4-44:,-53:5-54:6-55:7- These quotation marks are strange! |
Yeah, seems strange that the same culture is giving different results. May I know what version of .NET you're running the tests on and on what platform? I've made a slight change in the same code above. Was wondering if you can run it again? var number = 1234567;
number.ToString("N0", new CultureInfo("de-CH", true)).ToList().ForEach(x => Console.Write((int)x + ":" + x + "-"));
number.ToString("N2", new CultureInfo("de-CH", false)).ToList().ForEach(x => Console.Write((int)x + ":" + x + "-"));
number.ToString("N0", CultureInfo.GetCultureInfo("de-CH")).ToList().ForEach(x => Console.Write((int)x + ":" + x + "-"));
number.ToString("N2", CultureInfo.GetCultureInfo("de-CH")).ToList().ForEach(x => Console.Write((int)x + ":" + x + "-")); |
49:1-39:'-50:2-51:3-52:4-39:'-53:5-54:6-55:7- On Wed, Apr 16, 2014 at 1:04 PM, opiants [email protected] wrote:
|
I created the test in the Humanizer test project. On Wed, Apr 16, 2014 at 1:06 PM, Mehdi Khalili [email protected] wrote:
|
Strangely enough, running the tests on <= 3.5 will return the same format you are getting but on > 4.0 it returns what I'm getting. I don't think the framework version is the problem though cos the project's target framework is 4.0 and should be the same for everyone? But surely it has something to do with the framework but just can't figure out what and why. What do you suggest we do going forward? |
They've updated the number formats on newer OSes and frameworks and it seems that they won't bother updating the number formats to make it more consistent. https://connect.microsoft.com/VisualStudio/feedback/details/772498/inconsistent-formatting-behavior-of-double-tostring-in-net-3-5-vs-4-x I'll update the tests so it'll use a more consistent culture code and stop it from failing. |
Sorry I couldn't this yesterday. Had a crazy day! That was an interesting issue & good find. Thanks for the great work. Merged now. |
Thanks for the contribution. This is now available on NuGet as v1.23.1. |
No description provided.