Crates.io | whoa-german-numbers |
lib.rs | whoa-german-numbers |
version | 0.0.2 |
source | src |
created_at | 2022-07-18 17:42:45.2392 |
updated_at | 2022-07-18 17:54:55.765861 |
description | parse and interpret written german numbers |
homepage | |
repository | https://github.com/spencermountain/whoa-german-numbers |
max_upload_size | |
id | 627851 |
size | 24,191 |
Note it's my first crate, plz go easy on me!
parse textual german number formats in rust
Notably, numbers are not segmented by spaces or dashes in german - meaning they can be quite unruly sometimes.
extern crate whoa_german_numbers;
use whoa_german_numbers::{number_to_text, text_to_number};
let num = text_to_number("zwölf");
assert_eq!(num.unwrap(), 12);
let str = number_to_text(121);
assert_eq!(str, "einhunderteinundzwanzig");
*/
Convert written german numbers like "dreitausend" to integers (like 3000).
use whoa-german-numbers::text_to_number;
assert_eq!(text_to_number("fünf").unwrap(), 5);
assert_eq!(text_to_number("fünfte").unwrap(), 5); //ordinal support
assert_eq!(text_to_number("zweihundertzehn").unwrap(), 210);
Convert an integer (like 81), into a german text number, like "einundachtzig".
use whoa-german-numbers::number_to_text;
assert_eq!(number_to_text(81), "einundachtzig");
assert_eq!(number_to_text(5), "fünf");
assert_eq!(number_to_text(131), "einhunderteinunddreißig");
MIT