Crates.io | Lotus |
lib.rs | Lotus |
version | 0.2.1 |
source | src |
created_at | 2019-04-24 13:52:36.870492 |
updated_at | 2019-04-27 12:53:54.878052 |
description | Currency and Number formatting library |
homepage | |
repository | https://github.com/nerdypepper/lotus |
max_upload_size | |
id | 129878 |
size | 10,587 |
Basic currency and number formatting library.
Cargo.toml
[dependencies]
Lotus = "0.1.1"
extern crate Lotus;
use Lotus::*;
Here are some examples which illustrate the library functionality. Please read the documentation as well.
extern crate Lotus;
use Lotus::*;
// Builder format (recommended)
let rupee = LotusBuilder::default()
.symbol("Rs.")
.precision(1)
.format_positive("{symbol} {value}")
.format_negative("{symbol} ({value})")
.format_zero("{symbol} 0.00")
.decimal_str(".")
.thousand_str(" ")
.build()
.unwrap();
assert_eq!("Rs. 2 000 000.0", rupee.format(2_000_000));
assert_eq!("Rs. (2 000.0)", rupee.format(-2000));
assert_eq!("Rs. 0.00", rupee.format(0));
// Using Lotus::new()
let dollar = Lotus::new("$", 3); // Lotus::new(symbol, precision)
assert_eq!("$ 50,000.035", dollar.format(50_000.035));
// Using lotus! macro
let f = lotus!(150, "$"); // lotus!(number, symbol)
assert_eq!("$ 150.00", f);
let g = lotus!(2_000_000); // lotus!(number)
assert_eq!("2,000,000.00", g);