Skip to content

Commit 9af4e5c

Browse files
authored
Merge pull request #1 from OneBitSoftware/t-support-for-euro
Support for the euro currency
2 parents c70e165 + cc6734b commit 9af4e5c

6 files changed

Lines changed: 489 additions & 229 deletions

File tree

README.md

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,23 @@
55

66
A .NET library that converts currency values into words in Bulgarian for accounting purposes.
77

8-
Example: Input: `32048.27` Outpud: `тридесет и две хиляди и четиридесет и осем лева и 27 ст.`
8+
Example BGN: Input: `32048.27` Output: `тридесет и две хиляди и четиридесет и осем лева и 27 ст.`
9+
Example EUR: Input: `32048.27` Output: `тридесет и две хиляди и четиридесет и осем евро и 27 ц.`
910

1011
## Functionality
1112
- It takes into consideration the [grammatical gender](https://en.wikipedia.org/wiki/Grammatical_gender).
13+
- It supports negative values.
1214
- It writes decimal fractions in the short form: `X лева и ст.` when the value is above zero, and the full word when it is under the value of `1`: `девет стотинки`.
13-
- The current maximum value is `999999.99` and the minimum is `0.`.
15+
- The current maximum value is `999999.99` and the minimum is `-999999.99`.
16+
17+
## Supported currencies
18+
19+
The library supports the following currencies through predefined descriptors:
20+
21+
| Currency | Code | Major Unit | Minor Unit | Usage |
22+
|----------|------|------------|------------|-------|
23+
| Bulgarian Lev | BGN | лев/лева | стотинка/стотинки | `CurrencyDescriptor.Bgn` |
24+
| Euro | EUR | евро | евроцент/евроцента | `CurrencyDescriptor.Euro` |
1425

1526
## AI Story
1627
This project is my first attempt to build something with GitHub Copilot, with as little intervention as possible.
@@ -31,8 +42,28 @@ Or via the .NET Core command line interface:
3142
dotnet add package OneBitSoftware.Slovom
3243
```
3344

45+
## Usage
46+
47+
To use the library, call the `NumbersToWords.Convert` method, passing the amount and the desired currency descriptor.
48+
49+
```csharp
50+
using OneBitSoftware.Slovom;
51+
using OneBitSoftware.Slovom.Currencies;
52+
53+
// Convert BGN
54+
decimal amountBgn = 1234.56m;
55+
string resultBgn = NumbersToWords.Convert(amountBgn, CurrencyDescriptor.Bgn);
56+
// Result: "хиляда двеста тридесет и четири лева и 56 ст."
57+
58+
// Convert EUR
59+
decimal amountEur = 1234.56m;
60+
string resultEur = NumbersToWords.Convert(amountEur, CurrencyDescriptor.Euro);
61+
// Result: "хиляда двеста тридесет и четири евро и 56 ц."
62+
```
63+
3464
## Examples
3565

66+
## BGN examples
3667
|Input|Output|
3768
|--------|-------|
3869
|0|нула лева|
@@ -46,6 +77,21 @@ dotnet add package OneBitSoftware.Slovom
4677
|2014.78|две хиляди и четиринадесет лева и 78 ст.|
4778
|32478.27|тридесет и две хиляди четиристотин седемдесет и осем лева и 27 ст.|
4879

80+
81+
## EURO examples
82+
|Input| Output |
83+
|--------|-------------------------------------------------------------------|
84+
|0| нула евро |
85+
|1| едно евро |
86+
|2| две евро |
87+
|19| деветнадесет евро |
88+
|0.1| десет евроцента |
89+
|1.20| едно евро и 20 ц. |
90+
|1019.78| хиляда и деветнадесет евро и 78 ц. |
91+
|1119.78| хиляда сто и деветнадесет евро и 78 ц. |
92+
|2014.78| две хиляди и четиринадесет евро и 78 ц. |
93+
|32478.27| тридесет и две хиляди четиристотин седемдесет и осем евро и 27 ц. |
94+
4995
## Contributing
5096
Feel free to raise a PR to improve the code quality or add new features.
5197

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
namespace OneBitSoftware.Slovom.Currencies;
2+
3+
/// <summary>
4+
/// Represents a descriptor for a currency, providing information about major and minor currency units
5+
/// in both singular and plural forms, as well as an abbreviated symbol for minor currency units.
6+
/// </summary>
7+
public sealed record CurrencyDescriptor
8+
{
9+
private CurrencyDescriptor() { }
10+
11+
/// <summary>
12+
/// Gets the singular form of the major currency unit.
13+
/// </summary>
14+
public required string MajorCurrencyUnitSingular { get; init; }
15+
16+
/// <summary>
17+
/// Gets the plural form of the major currency unit.
18+
/// </summary>
19+
public required string MajorCurrencyUnitPlural { get; init; }
20+
21+
/// <summary>
22+
/// Gets the plural form of the minor currency unit.
23+
/// </summary>
24+
public required string MinorCurrencyUnitPlural { get; init; }
25+
26+
/// <summary>
27+
/// Gets the singular form of the minor currency unit.
28+
/// </summary>
29+
public required string MinorCurrencyUnitSingular { get; init; }
30+
31+
/// <summary>
32+
/// Gets the abbreviated form of the minor currency unit.
33+
/// </summary>
34+
public required string MinorCurrencyUnitAbbreviated { get; init; }
35+
36+
/// <summary>
37+
/// Gets the vocabulary containing word representations for numbers and units in a specific language or currency context.
38+
/// </summary>
39+
public required NumberWordsVocabulary Vocabulary { get; init; }
40+
41+
/// <summary>
42+
/// Gets the currency descriptor for Bulgarian Lev (BGN).
43+
/// </summary>
44+
public static CurrencyDescriptor Bgn => new()
45+
{
46+
MajorCurrencyUnitSingular = " лев",
47+
MajorCurrencyUnitPlural = " лева",
48+
MinorCurrencyUnitPlural = " стотинки",
49+
MinorCurrencyUnitSingular = " стотинка",
50+
MinorCurrencyUnitAbbreviated = "ст.",
51+
Vocabulary = new NumberWordsVocabulary
52+
{
53+
MinorCurrencyUnitSingular = "една",
54+
NumbersZeroToNineteen = ["нула", "един", "два", "три", "четири", "пет", "шест", "седем", "осем", "девет", "десет", "единадесет", "дванадесет", "тринадесет", "четиринадесет", "петнадесет", "шестнадесет", "седемнадесет", "осемнадесет", "деветнадесет"],
55+
SingleDigitsNeutral = ["нула", "едно", "две", "три", "четири", "пет", "шест", "седем", "осем", "девет"],
56+
NumbersTenToNineteen = ["десет", "единадесет", "дванадесет", "тринадесет", "четиринадесет", "петнадесет", "шестнадесет", "седемнадесет", "осемнадесет", "деветнадесет"],
57+
TensMultiples = ["", "десет", "двадесет", "тридесет", "четиридесет", "петдесет", "шестдесет", "седемдесет", "осемдесет", "деветдесет"],
58+
HundredsMultiples = ["", "сто", "двеста", "триста", "четиристотин", "петстотин", "шестстотин", "седемстотин", "осемстотин", "деветстотин"]
59+
}
60+
};
61+
62+
/// <summary>
63+
/// Gets the currency descriptor for Euro (EUR).
64+
/// </summary>
65+
public static CurrencyDescriptor Euro => new()
66+
{
67+
MajorCurrencyUnitSingular = " евро",
68+
MajorCurrencyUnitPlural = " евро",
69+
MinorCurrencyUnitPlural = " евроцента",
70+
MinorCurrencyUnitSingular = " евроцент",
71+
MinorCurrencyUnitAbbreviated = "ц.",
72+
Vocabulary = new NumberWordsVocabulary
73+
{
74+
MinorCurrencyUnitSingular = "един",
75+
NumbersZeroToNineteen = ["нула", "едно", "две", "три", "четири", "пет", "шест", "седем", "осем", "девет", "десет", "единадесет", "дванадесет", "тринадесет", "четиринадесет", "петнадесет", "шестнадесет", "седемнадесет", "осемнадесет", "деветнадесет"],
76+
SingleDigitsNeutral = ["нула", "едно", "две", "три", "четири", "пет", "шест", "седем", "осем", "девет"],
77+
NumbersTenToNineteen = ["десет", "единадесет", "дванадесет", "тринадесет", "четиринадесет", "петнадесет", "шестнадесет", "седемнадесет", "осемнадесет", "деветнадесет"],
78+
TensMultiples = ["", "десет", "двадесет", "тридесет", "четиридесет", "петдесет", "шестдесет", "седемдесет", "осемдесет", "деветдесет"],
79+
HundredsMultiples = ["", "сто", "двеста", "триста", "четиристотин", "петстотин", "шестстотин", "седемстотин", "осемстотин", "деветстотин"]
80+
}
81+
};
82+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
namespace OneBitSoftware.Slovom.Currencies;
2+
3+
/// <summary>
4+
/// Represents a vocabulary collection for converting numbers and currency into words.
5+
/// </summary>
6+
/// <remarks>
7+
/// This class defines the language-specific words used for numbers, single digits, tens,
8+
/// hundreds, and numbers between zero and nineteen. It is intended to support currency and
9+
/// numeric transformation into word representations.
10+
/// </remarks>
11+
public sealed record NumberWordsVocabulary
12+
{
13+
internal NumberWordsVocabulary() { }
14+
15+
/// <summary>
16+
/// Gets or inits the word representation for the singular form of the minor currency unit.
17+
/// </summary>
18+
public required string MinorCurrencyUnitSingular { get; init; }
19+
20+
/// <summary>
21+
/// Gets or inits the words for numbers from zero to nineteen.
22+
/// </summary>
23+
public required string[] NumbersZeroToNineteen { get; init; }
24+
25+
/// <summary>
26+
/// Gets or inits the words for single digits in neutral form.
27+
/// </summary>
28+
public required string[] SingleDigitsNeutral { get; init; }
29+
30+
/// <summary>
31+
/// Gets or inits the words for numbers from ten to nineteen.
32+
/// </summary>
33+
public required string[] NumbersTenToNineteen { get; init; }
34+
35+
/// <summary>
36+
/// Gets or inits the words for multiples of ten.
37+
/// </summary>
38+
public required string[] TensMultiples { get; init; }
39+
40+
/// <summary>
41+
/// Gets or inits the words for multiples of a hundred.
42+
/// </summary>
43+
public required string[] HundredsMultiples { get; init; }
44+
}

0 commit comments

Comments
 (0)