2 unstable releases

0.2.1 Apr 27, 2019
0.1.1 Apr 24, 2019

#100 in Value formatting

Download history 27/week @ 2021-10-06 30/week @ 2021-10-13 37/week @ 2021-10-20 33/week @ 2021-10-27 59/week @ 2021-11-03 57/week @ 2021-11-10 53/week @ 2021-11-17 18/week @ 2021-11-24 25/week @ 2021-12-01 27/week @ 2021-12-08 24/week @ 2021-12-15 13/week @ 2021-12-22 15/week @ 2021-12-29 12/week @ 2022-01-05 32/week @ 2022-01-12 8/week @ 2022-01-19

335 downloads per month

MIT license

10KB
153 lines

Lotus

Basic currency and number formatting library.

Installation

  1. Add the following lines to your Cargo.toml
[dependencies]
Lotus = "0.1.1" 
  1. Use it in your crate:
extern crate Lotus;
use Lotus::*;

Usage

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);

Other Programming Languages

Dependencies

~2MB
~50K SLoC