Crates.io | french-numbers |
lib.rs | french-numbers |
version | 1.2.0 |
source | src |
created_at | 2017-04-22 19:42:04.512656 |
updated_at | 2023-10-06 22:58:42.314874 |
description | Represent numbers in French language |
homepage | https://rfc1149.net/devel/french-numbers.html |
repository | |
max_upload_size | |
id | 11576 |
size | 773,900 |
This crate transforms a number into its French representation.
In your Cargo.toml
, put:
[dependencies]
french-numbers = "1.2.0"
You can then use the french_number
function from the french_numbers
crate
to format any integer into the beautiful French romance language:
use french_numbers::french_number;
assert_eq!(french_number(&71), "soixante-et-onze");
assert_eq!(french_number(&1001), "mille-un");
assert_eq!(french_number(&-200001), "moins deux-cent-mille-un");
assert_eq!(french_number(&-200000001), "moins deux-cents-millions-un");
assert_eq!(french_number(&-204000001), "moins deux-cent-quatre-millions-un");
You can also request the use of the feminine form, or prefer the previous way of writing numbers predating the 1990 orthographic reform:
use french_numbers::*;
assert_eq!(french_number_options(&37251061, &POST_REFORM_MASCULINE),
"trente-sept-millions-deux-cent-cinquante-et-un-mille-soixante-et-un");
assert_eq!(french_number_options(&37251061, &POST_REFORM_FEMININE),
"trente-sept-millions-deux-cent-cinquante-et-un-mille-soixante-et-une");
assert_eq!(french_number_options(&37251061, &PRE_REFORM_FEMININE),
"trente-sept millions deux cent cinquante et un mille soixante et une");
assert_eq!(french_number_options(&37251061, &PRE_REFORM_MASCULINE),
"trente-sept millions deux cent cinquante et un mille soixante et un")
An example program can dump particular numbers, with various options combinations:
% cargo run --bin french-numbers --features cli -- --help
Represent numbers in French language
Usage: french-numbers [OPTIONS] <LOW> [HIGH]
Arguments:
<LOW>
Number (or low bound) to use
If no high bound is supplied, this will be the only number displayed.
[HIGH]
Optional high bound
Options:
-f, --feminine
Use the feminine declination
-p, --prefix
Prefix output with the numerical representation
-r, --no-reform
Use the pre-1990 orthographic reform writing
By default, all numbers are separated by dashes. Pre-1990, only numbers smaller than 100 were separated by dashes, others words were separated by spaces.
-h, --help
Print help (see a summary with '-h')
-V, --version
Print version