Skip to content

Commit

Permalink
Bugfix/1159 bulgarian number fix (#1193)
Browse files Browse the repository at this point in the history
  • Loading branch information
agentdiscowing authored Feb 12, 2024
1 parent 534b65f commit 89491d2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class NumberToWordsTests

[Theory]
[InlineData(0, "нула")]
[InlineData(1, "един")]
[InlineData(1, "едно")]
[InlineData(10, "десет")]
[InlineData(11, "единадесет")]
[InlineData(12, "дванадесет")]
Expand Down Expand Up @@ -46,6 +46,7 @@ public class NumberToWordsTests
[InlineData(4000210, "четири милиона двеста и десет")]
[InlineData(5200, "пет хиляди и двеста")]
[InlineData(1125000, "един милион и сто двадесет и пет хиляди")]
[InlineData(1000000000, "един милиард")]
public void ToWordsBg(long number, string expected)
{
Assert.Equal(expected, number.ToWords());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ internal class BulgarianNumberToWordsConverter : GenderedNumberToWordsConverter
{
private static readonly string[] UnitsMap =
{
"нула", "един", "две", "три", "четири", "пет", "шест", "седем", "осем", "девет", "десет", "единадесет",
"нула", "едно", "две", "три", "четири", "пет", "шест", "седем", "осем", "девет", "десет", "единадесет",
"дванадесет", "тринадесет", "четиринадесет", "петнадесет", "шестнадесет", "седемнадесет", "осемнадесет",
"деветнадесет"
};
Expand All @@ -21,14 +21,12 @@ internal class BulgarianNumberToWordsConverter : GenderedNumberToWordsConverter
"осемстотин", "деветстотин"
};


private static readonly string[] HundredsOrdinalMap =
{
String.Empty, "стот", "двест", "трист", "четиристот", "петстот", "шестстот", "седемстот", "осемстот",
"деветстот"
};


private static readonly string[] UnitsOrdinal =
{
string.Empty, "първ", "втор", "трет", "четвърт", "пет", "шест", "седм", "осм", "девeт", "десeт",
Expand Down Expand Up @@ -74,8 +72,7 @@ private string Convert(long input, GrammaticalGender gender, bool isOrdinal, boo

if ((input / 1000000000) > 0)
{
parts.Add(Convert(input / 1000000000, gender, false) +
$" {(input < 2000000000 ? "милиард" : "милиарда")}");
parts.Add(input < 2000000000 ? "един милиард" : Convert(input / 1000000000, gender, false) + " милиарда");

if (isOrdinal)
lastOrdinalSubstitution = Convert(input / 1000000000, gender, false) + " милиард" +
Expand All @@ -85,7 +82,7 @@ private string Convert(long input, GrammaticalGender gender, bool isOrdinal, boo

if ((input / 1000000) > 0)
{
parts.Add(Convert(input / 1000000, gender, false) + $" {(input < 2000000 ? "милион" : "милиона")}");
parts.Add(input < 2000000 ? "един милион" : Convert(input / 1000000, gender, false) + " милиона");

if (isOrdinal)
lastOrdinalSubstitution = Convert(input / 1000000, gender, false) + " милион" +
Expand Down

0 comments on commit 89491d2

Please sign in to comment.