Documentation
¶
Overview ¶
Package money represents Brazilian currency amounts as integer centavos.
VTEX is inconsistent about how it reports prices: the catalog search APIs return decimal reais as float64 (153.72) while the checkout orderForm and delivery simulation return integer centavos (15372). Converting at the API boundary means no downstream code ever handles a float price, which removes a class of rounding bug from checkout arithmetic.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Centavos ¶
type Centavos int64
Centavos is an amount in Brazilian centavos. It is an integer type, so it marshals to JSON as a plain number and agent-facing output stays arithmetic-safe.
func Reais ¶
Reais converts a decimal-reais amount to Centavos, rounding half away from zero. Rounding matters: 0.1+0.2 is 0.30000000000000004 in float64, and truncating would price it at 29 centavos.
func (Centavos) Reais ¶
Reais returns the amount as decimal reais. Use it only at boundaries that demand a float, such as building a VTEX request body that expects one.
func (*Centavos) UnmarshalJSON ¶
UnmarshalJSON accepts both integer and decimal encodings of a centavo amount. VTEX is inconsistent: the checkout orderForm sends 15372 while the OMS order list sends 26511.0 for the same kind of value. Both mean centavos; only the JSON encoding differs.