money

package
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 4 Imported by: 0

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

func Reais(r float64) Centavos

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

func (c Centavos) Reais() float64

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) String

func (c Centavos) String() string

String renders the amount in pt-BR currency format: R$1.234.567,89

func (*Centavos) UnmarshalJSON

func (c *Centavos) UnmarshalJSON(data []byte) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL