1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//! Formatting helpers for monetary amounts, rates, and decimal numbers.
//!
//! All functions accept raw integer representations — cents for monetary values
//! and scaled integers for rates — and return formatted `String`s suitable for
//! insertion into NF-e XML elements.
/// Format a cents integer to a decimal string with the given number of decimal places.
///
/// # Examples
///
/// ```
/// use fiscal_core::format_utils::format_cents;
/// assert_eq!(format_cents(1050, 2), "10.50");
/// assert_eq!(format_cents(100000, 10), "1000.0000000000");
/// ```
/// Format a cents integer to a decimal string with 2 decimal places.
///
/// # Examples
///
/// ```
/// use fiscal_core::format_utils::format_cents_2;
/// assert_eq!(format_cents_2(1050), "10.50");
/// assert_eq!(format_cents_2(0), "0.00");
/// ```
/// Format a cents integer to a decimal string with 10 decimal places (for unit prices).
///
/// # Examples
///
/// ```
/// use fiscal_core::format_utils::format_cents_10;
/// assert_eq!(format_cents_10(100000), "1000.0000000000");
/// ```
/// Format a floating-point number with `decimal_places` decimal places.
///
/// # Examples
///
/// ```
/// use fiscal_core::format_utils::format_decimal;
/// assert_eq!(format_decimal(3.14159, 2), "3.14");
/// ```
/// Format a rate stored as hundredths of a percent to a decimal string.
///
/// For example, `1800` (= 18%) with 4 decimal places → `"18.0000"`.
///
/// # Examples
///
/// ```
/// use fiscal_core::format_utils::format_rate;
/// assert_eq!(format_rate(1800, 4), "18.0000");
/// assert_eq!(format_rate(750, 2), "7.50");
/// ```
/// Format a rate (stored as hundredths) with 4 decimal places.
///
/// # Examples
///
/// ```
/// use fiscal_core::format_utils::format_rate_4;
/// assert_eq!(format_rate_4(1800), "18.0000");
/// ```
/// Format a PIS/COFINS rate stored as `value × 10 000` to a 4-decimal string.
///
/// For example, `16500` (= 1.65%) → `"1.6500"`.
///
/// # Examples
///
/// ```
/// use fiscal_core::format_utils::format_rate4;
/// assert_eq!(format_rate4(16500), "1.6500");
/// ```
/// Format an optional cents value to a decimal string, returning `None` when the
/// input is `None`.
/// Format an optional cents value to a decimal string, defaulting to `"0.00"` (or
/// `"0.` + `n` zeros`"`) when the input is `None`.
/// Format an optional `rate4` value (scaled by 10 000) to a 4-decimal string,
/// defaulting to `"0.0000"` when the input is `None`.