Skip to content

OneBitSoftware/OneBitSoftware.Slovom

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OneBitSoftware.Slovom

test

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

Example BGN: Input: 32048.27 Output: тридесет и две хиляди и четиридесет и осем лева и 27 ст. Example EUR: Input: 32048.27 Output: тридесет и две хиляди и четиридесет и осем евро и 27 ц.

Functionality

  • It takes into consideration the grammatical gender.
  • It supports negative values.
  • 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: девет стотинки.
  • The current maximum value is 999999.99 and the minimum is -999999.99.

Supported currencies

The library supports the following currencies through predefined descriptors:

Currency Code Major Unit Minor Unit Usage
Bulgarian Lev BGN лев/лева стотинка/стотинки CurrencyDescriptor.Bgn
Euro EUR евро евроцент/евроцента CurrencyDescriptor.Euro

AI Story

This project is my first attempt to build something with GitHub Copilot, with as little intervention as possible. GitHub Copilot just couldn't understand my requirements thoroughly enough and it never gave something that satisfies all requirements together. I made many attempts to improve functions with detailed prompts, but code was always unsatisfactory. I did my best to not give up on it, however my patience was over at one point.

Generating InlineData for the tests failed into an infinite loop (and the token limits kicked in). Nothing generated as code passed all the tests no matter how I structured prompts. Prompting it to fix the code so tests pass never got the necessary results.

I eventually had to correct the code myself. The end result is an abomination, but it works. I still feel that I would have spent less time writing it from scratch.

Installation

You can install the OneBitSoftware.Slovom assembly through the NuGet package NuGet:

Install-Package OneBitSoftware.Slovom

Or via the .NET Core command line interface:

dotnet add package OneBitSoftware.Slovom

Usage

To use the library, call the NumbersToWords.Convert method, passing the amount and the desired currency descriptor.

using OneBitSoftware.Slovom;
using OneBitSoftware.Slovom.Currencies;

// Convert BGN
decimal amountBgn = 1234.56m;
string resultBgn = NumbersToWords.Convert(amountBgn, CurrencyDescriptor.Bgn);
// Result: "хиляда двеста тридесет и четири лева и 56 ст."

// Convert EUR
decimal amountEur = 1234.56m;
string resultEur = NumbersToWords.Convert(amountEur, CurrencyDescriptor.Euro);
// Result: "хиляда двеста тридесет и четири евро и 56 ц."

Examples

BGN examples

Input Output
0 нула лева
1 един лев
2 два лева
19 деветнадесет лева
0.1 десет стотинки
1.20 един лев и 20 ст.
1019.78 хиляда и деветнадесет лева и 78 ст.
1119.78 хиляда сто и деветнадесет лева и 78 ст.
2014.78 две хиляди и четиринадесет лева и 78 ст.
32478.27 тридесет и две хиляди четиристотин седемдесет и осем лева и 27 ст.

EURO examples

Input Output
0 нула евро
1 едно евро
2 две евро
19 деветнадесет евро
0.1 десет евроцента
1.20 едно евро и 20 ц.
1019.78 хиляда и деветнадесет евро и 78 ц.
1119.78 хиляда сто и деветнадесет евро и 78 ц.
2014.78 две хиляди и четиринадесет евро и 78 ц.
32478.27 тридесет и две хиляди четиристотин седемдесет и осем евро и 27 ц.

Contributing

Feel free to raise a PR to improve the code quality or add new features.

Credits

Inspired by:

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages