Input | Output |
---|---|
0.1 | 100m |
0.01 | 10m |
0.001 | 1m |
0.000_000_001 | 1n |
0.000_000_000_000_000_000_000_000_000_1 | 100q |
Input | Output |
---|---|
1_000 | 1K |
1_000_000 | 1M |
1_090 | 1.09K |
001_090 | 1.09K |
123_000_000_000_000_000_000 | 123E |
-123_000_000_000_000_000_000 | -123E |
1_000_000_000_000_000_000_000_000_000_000 | 1Q |
Input | Output |
---|---|
1K | 1000 |
1.09K | 1090 |
1_090 | 1.09K |
123E | 123_000_000_000_000_000_000 |
1Q | 1_000_000_000_000_000_000_000_000_000_000 |
fn main() {
// numbers greater then 1:
println!("{}", 123.abbreviate_number(&Default::default())); // result: 123
println!("{}", 123_000.0.abbreviate_number(&Default::default())); //result: 123K
println!("{}", "1K".unabbreviate_number(&Default::default())); //result: 1000.0
println!("{}", "1M".unabbreviate_number(&Default::default())); //result: 1000000.0
// numbers less then 1:
println!("{}", (0.1).abbreviate_number(&Default::default())); // result: 100m
println!("{}",(0.000_000_001).abbreviate_number(&Default::default())); //result: 1n
println!("{}", "111z".unabbreviate_number(&Default::default())); // result : 0.000000000000000000111
println!("{}", "100n".unabbreviate_number(&Default::default())); // result : 0.0000001
}
fn main() {
let big_num: i128 = 999_509_999_999_999_000_123_123_000_000_123;
println!("{}", big_num.abbreviate_number(&Default::default())); // result : 999.5Q
}
fn main(){
assert_eq!(
"100-q",
(0.000_000_000_000_000_000_000_000_000_1).abbreviate_number(&AbbreviationOptions {
padding: 0,
separator: "-".to_string()
})
);
assert_eq!(
"-100 q",
(-0.000_000_000_000_000_000_000_000_000_1).abbreviate_number(&AbbreviationOptions {
padding: 3,
..Default::default()
})
);
}
use rs_abbreviation_number::time::*;
fn main() {
let seconds=Time::from_second(34_536_000);
assert_eq!(1,seconds.get_year());
assert_eq!(12,seconds.get_month());
let hours=Time::from_hour(9593);
assert_eq!(1,hours.get_year());
assert_eq!(12,hours.get_month());
assert_eq!(360,hours.get_day());
}
- Symbols Are Case-Sensitive And
- Program Will Automaticly Remove Leading Zero (001 Will Become 1 and etc)
- Time Estimation Is Not As Accurate As The Name Suggests And It May Differ From The Exact Value
Symbol | Base |
---|---|
q | |
r | |
y | |
z | |
a | |
f | |
p | |
n | |
μ | |
m | |
K | |
M | |
G | |
T | |
P | |
E | |
Z | |
Y | |
R | |
Q |
- [ ] Optimize Code
- [ ] Create Custom Symbols
- [x] Custom separator pass by option
- [ ] Create Unit Conversion