Expand description
§summa-propisyu
Money amounts in words for invoices, contracts and receipts, in five languages: Russian, Ukrainian, Lithuanian, English and French. No dependencies.
[dependencies]
summa-propisyu = "0.1"use summa_propisyu::{amount_in_words, Currency, Lang};
assert_eq!(
amount_in_words("1521.40", Currency::Rub, Lang::Ru).unwrap(),
"Одна тысяча пятьсот двадцать один рубль 40 копеек"
);
assert_eq!(
amount_in_words("22.02", Currency::Uah, Lang::Uk).unwrap(),
"Двадцять дві гривні 02 копійки"
);
assert_eq!(
amount_in_words("21.21", Currency::Kzt, Lang::Ru).unwrap(),
"Двадцать один тенге 21 тиын"
);
assert_eq!(
amount_in_words("12.11", Currency::Eur, Lang::Lt).unwrap(),
"Dvylika eurų 11 centų"
);
assert_eq!(
amount_in_words("1000000", Currency::Eur, Lang::Fr).unwrap(),
"Un million d'euros et 00 centimes"
);§Why another one
Spelling out a number is the easy part. The hard part in an invoice is the currency name next to it, because it has to agree with the number:
| Amount | Russian | Ukrainian | Lithuanian |
|---|---|---|---|
| 1 | один рубль, одна гривна | одна гривня, одне євро | vienas euras, viena grivina |
| 2 | два рубля, две гривны | дві гривні, два євро | du eurai, dvi grivinos |
| 5 | пять рублей, пять гривен | п’ять гривень | penki eurai |
| 11 | одиннадцать рублей | одинадцять гривень | vienuolika eurų |
| 21 | двадцать один рубль | двадцять одна гривня | dvidešimt vienas euras |
Gender changes the number itself (один / одна, du / dvi), and there are three plural forms, not two. Tenge and euro do not change in Russian at all. French needs “un million **d’**euros” but “un million deux euros”, and “quatre-vingts euros” but “quatre-vingt-un euros”. All of this is handled.
§Currencies
Eur, Usd, Gbp, Pln, Uah, Rub, Byn, Kzt in every language.
Lang and Currency also parse from strings: "ru".parse::<Lang>(), "KZT".parse::<Currency>().
§Options
use summa_propisyu::{amount_in_words_with, cents_in_words, Currency, Lang, Minor, Options};
// kopecks in words instead of digits
let opts = Options { minor: Minor::Words, capitalize: true };
assert_eq!(
amount_in_words_with("31.31", Currency::Uah, Lang::Uk, opts).unwrap(),
"Тридцять одна гривня тридцять одна копійка"
);
// money stored as integer cents
assert_eq!(
cents_in_words(1599, Currency::Usd, Lang::Ru, Options { minor: Minor::None, capitalize: false }),
"пятнадцать долларов"
);The amount string may use a dot or a comma and spaces between thousands
("1 521,40"). It is rounded half up to two decimals, so "99.995" becomes 100.00.
Numbers without currency:
use summa_propisyu::{number_in_words, Gender, Lang};
assert_eq!(number_in_words(2, Lang::Ru, Gender::Feminine).unwrap(), "две");
assert_eq!(number_in_words(2000, Lang::Uk, Gender::Masculine).unwrap(), "дві тисячі");
assert_eq!(number_in_words(91, Lang::Fr, Gender::Masculine).unwrap(), "quatre-vingt-onze");Range: up to 999 999 999 999 999 in both directions.
§Same rules in Python
The crate is a port of the Python package summa-propisyu, and both give the same output. Plain number words in all five languages were checked against num2words on 8 000 values.
§Online version
An online converter with the same languages and currencies is at utilixi.com:
| Language | Converter |
|---|---|
| Русский | Сумма прописью онлайн |
| Українська | Сума прописом онлайн |
| Lietuvių | Suma žodžiais |
| English | Number to words |
| Français | Nombre en lettres |
§License
MIT
Structs§
- Options
- Formatting options for
amount_in_words_with.
Enums§
- Currency
- Supported currencies.
- Error
- Errors returned by this crate.
- Gender
- Grammatical gender of the counted noun (matters for ru, uk, lt).
- Lang
- Output language.
- Minor
- How to write the minor unit (kopecks, cents).
Functions§
- amount_
in_ words - Amount in words with default options: minor units in digits, capitalized.
- amount_
in_ words_ with - Amount in words with explicit
Options. - cents_
in_ words - Same as
amount_in_words_with, but the amount is given in minor units (152140 = 1521.40). Useful when money is stored as integers. - number_
in_ words - A whole number in words.
gendermatters for ru, uk and lt only.