Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.stric.io/llms.txt

Use this file to discover all available pages before exploring further.

Toda quantia monetária na API Stric é representada como string em centavos. Não usamos floats nem reais com vírgula.

Por quê?

Floats causam erros de precisão clássicos em sistemas financeiros:
0.1 + 0.2 === 0.3 // false  →  resultado: 0.30000000000000004
Strings em centavos eliminam o problema: você trabalha com inteiros nos seus cálculos e só formata para apresentação ao usuário.

Tabela de conversão

Real (BRL)Stric (string)Decimal (cents)
R$ 1,00"100"100
R$ 10,50"1050"1.050
R$ 1.234,56"123456"123.456
R$ 0,01"1"1

Funções de conversão

// BRL → centavos (string)
function realToCents(real) {
  return Math.round(real * 100).toString();
}
realToCents(10.50); // "1050"

// centavos (string) → BRL formatado
function centsToReal(cents) {
  const value = parseInt(cents, 10) / 100;
  return value.toLocaleString("pt-BR", {
    style: "currency",
    currency: "BRL",
  });
}
centsToReal("1050"); // "R$ 10,50"

Exemplos no contexto da API

POST /v1/charges
{
  "variant": "simple",
  "amountCents": "2500",
  "...": "..."
}
Cria uma cobrança de R$ 25,00.
Trabalhe com BigInt (JS), Decimal (Python), *big.Int (Go) ou similares quando lidar com valores grandes. Mesmo que centavos como string já evitem o problema dos floats, valores acima de 2^53 podem estourar Number em JS.