decimal

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package decimal reads and writes non-negative decimal numbers as whole counts of a small unit, so that money and quantities never pass through a floating point number. Input: a decimal string ("12", "12.5"). Output: a *big.Int count of 10^-scale, or a decimal string with a fixed number of places.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatScaled

func FormatScaled(n *big.Int, scale int) string

FormatScaled writes n (a count of 10^-scale) as a decimal string with scale places.

func ParseScaled

func ParseScaled(s string, scale int) (*big.Int, bool)

ParseScaled reads a non-negative decimal into an integer count of 10^-scale. It fails for a sign, an exponent, anything but digits and one point, and for more decimal places than scale.

func SumCents

func SumCents(items []Item) (int64, bool)

SumCents is the sum of quantity times price over the items, rounded half up to whole cents once at the end (the same rule as the total of an order). ok is false when a number is not a valid decimal.

Types

type Item

type Item struct{ Qty, Price string }

Item is a quantity (three places) and a unit price (two places).

Jump to

Keyboard shortcuts

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