Skip to main content

number_to_currency

Function number_to_currency 

Source
pub fn number_to_currency(value: impl Display, unit: &str) -> String
Expand description

Two decimals, thousands grouped, unit first: 1234.5 with "$" becomes $1,234.50, -3 becomes -$3.00 (Rails’ number_to_currency).

For amounts stored in cents, divide first: number_to_currency(cents as f64 / 100.0, "€").

§Examples

assert_eq!(ocre::helpers::number_to_currency(1234.5, "€"), "€1,234.50");