| 1 |
// This file is part of ICU4X. For terms of use, please see the file |
| 2 |
// called LICENSE at the top level of the ICU4X source tree |
| 3 |
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). |
| 4 |
|
| 5 |
// In computers, monetary values are sometimes stored as integers representing one ten-thousandth |
| 6 |
// (one permyriad) of a monetary unit. FixedDecimal enables a cheap representation of these |
| 7 |
// amounts, also while retaining trailing zeros. |
| 8 |
|
| 9 |
#![no_main] // https://github.com/unicode-org/icu4x/issues/395 |
| 10 |
icu_benchmark_macros::instrument!(); |
| 11 |
|
| 12 |
use fixed_decimal::Decimal; |
| 13 |
use writeable::Writeable; |
| 14 |
|
| 15 |
fn main() { |
| 16 |
let monetary_int = 19_9500; |
| 17 |
let fixed_decimal = { |
| 18 |
let mut fixed_decimal = Decimal::from(monetary_int); |
| 19 |
fixed_decimal.multiply_pow10(-4); |
| 20 |
fixed_decimal |
| 21 |
}; |
| 22 |
|
| 23 |
assert_eq!(fixed_decimal.write_to_string(), "19.9500"); |
| 24 |
} |