Documentation
¶
Overview ¶
Package bigdecimal provides arbitrary-precision decimal arithmetic operations for financial calculations.
Index ¶
Constants ¶
View Source
const ( // AllowedCharacters defines the set of characters permitted in a BigDecimal string. AllowedCharacters = "0123456789.-eE" // BigDecRegEx is the regular expression that a valid BigDecimal string must match. BigDecRegEx = "-?(?:[0|1-9]\\d*)(?:\\.\\d+)?(?:[eE][+\\-]?\\d+)?" // Precision specifies the bit precision used for internal big.Float calculations. Precision = 512 )
Variables ¶
View Source
var ( // ErrInvalidZeroValue indicates the value string represents zero or is invalid zero. ErrInvalidZeroValue = errors.New("value cannot be zero") )
Functions ¶
This section is empty.
Types ¶
type BigDecimal ¶
type BigDecimal struct {
Scale int
Precision int
UnscaledValue string
Sign int // 1 for negative, 0 for positive
}
BigDecimal represents a high-precision decimal value with scale, precision, and sign.
func NewBigDecimal ¶
func NewBigDecimal(value string) (bd *BigDecimal, err error)
NewBigDecimal creates a BigDecimal from the given string, validating format and scale.
func (*BigDecimal) GetScaledValue ¶
func (bd *BigDecimal) GetScaledValue() string
GetScaledValue returns the decimal as a string without scientific notation, scaled by its Scale.
type ErrInvalidCharacter ¶
type ErrInvalidCharacter struct {
Allowed string
}
ErrInvalidCharacter is returned when a string contains disallowed characters.
func (ErrInvalidCharacter) Error ¶ added in v0.1.13
func (e ErrInvalidCharacter) Error() string
Error implements the error interface for ErrInvalidCharacter
Click to show internal directories.
Click to hide internal directories.