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

billions and millions greater than 2 #630

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ public class NumberToWordsTests
[InlineData(1000, "mil")]
[InlineData(100000, "cem mil")]
[InlineData(1000000, "um milhão")]
[InlineData(2000000, "dois milhões")]
[InlineData(10000000, "dez milhões")]
[InlineData(100000000, "cem milhões")]
[InlineData(1000000000, "um bilhão")]
[InlineData(2000000000, "dois bilhões")]
[InlineData(111, "cento e onze")]
[InlineData(1111, "mil cento e onze")]
[InlineData(111111, "cento e onze mil cento e onze")]
Expand All @@ -35,6 +37,7 @@ public class NumberToWordsTests
[InlineData(12345, "doze mil trezentos e quarenta e cinco")]
[InlineData(123456, "cento e vinte e três mil quatrocentos e cinquenta e seis")]
[InlineData(1234567, "um milhão duzentos e trinta e quatro mil quinhentos e sessenta e sete")]
[InlineData(2234567, "dois milhões duzentos e trinta e quatro mil quinhentos e sessenta e sete")]
[InlineData(12345678, "doze milhões trezentos e quarenta e cinco mil seiscentos e setenta e oito")]
[InlineData(123456789, "cento e vinte e três milhões quatrocentos e cinquenta e seis mil setecentos e oitenta e nove")]
[InlineData(1234567890, "um bilhão duzentos e trinta e quatro milhões quinhentos e sessenta e sete mil oitocentos e noventa")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public override string Convert(int number, GrammaticalGender gender)
if ((number / 1000000000) > 0)
{
// gender is not applied for billions
parts.Add(number / 1000000000 > 2
parts.Add(number / 1000000000 == 1
? string.Format("{0} bilhões", Convert(number / 1000000000, GrammaticalGender.Masculine))
: string.Format("{0} bilhão", Convert(number / 1000000000, GrammaticalGender.Masculine)));
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use interpolated string:

var genderMark = number / 1000000000 == 1 ? "ões" : "ão";
parts.Add($"{Convert(number / 1000000000, GrammaticalGender.Masculine)} bilh{genderMark}");

And you can use something similar for millions (or even make it a private static method).


Expand All @@ -36,7 +36,7 @@ public override string Convert(int number, GrammaticalGender gender)
if ((number / 1000000) > 0)
{
// gender is not applied for millions
parts.Add(number / 1000000 > 2
parts.Add(number / 1000000 == 1
? string.Format("{0} milhões", Convert(number / 1000000, GrammaticalGender.Masculine))
: string.Format("{0} milhão", Convert(number / 1000000, GrammaticalGender.Masculine)));

Expand Down Expand Up @@ -159,4 +159,4 @@ private static string ApplyOrdinalGender(string toWords, GrammaticalGender gende
return toWords;
}
}
}
}