#money #format #string #reference #prints

format_money

A simple function that takes a string reference &str and returns a String with money format $ #'###,###.##

2 releases

0.1.1 Jun 30, 2020
0.1.0 Jun 30, 2020

#248 in Finance

Download history 28/week @ 2024-09-23

79 downloads per month

MIT license

6KB
89 lines

format_money

format_money is a simple function that takes a string reference &str as a number, evaluates it and returns a String with money format $ #'###,###.##

Examples:

use format_money::format_money;

fn main() {
    println!("{}",format_money("0100010"));
    //it prints $ 100,010.00

   assert_eq!(format_money("."), "$ 0.00");

   assert_eq!(format_money("000.157"), "$ 0.15");

   assert_eq!(format_money("103"), "$ 103.00");

   assert_eq!(format_money("001000000334533461000813.5792"), "$ 1,000'000,334'533,461'000,813.57");

   assert_eq!(format_money("0000.00"), "$ 0.00");

   assert_eq!(format_money("00000010.00000"), "$ 10.00");

   assert_eq!(format_money("0100.00000"), "$ 100.00");

   assert_eq!(format_money("F1c0.0A000"), "$ 0.00");
}


lib.rs:

format_money is a simple function that takes a string reference &str as a number, evaluates it and returns a String with money format $ #'###,###.##

No runtime deps