Documentation ¶
Overview ¶
Package decimal provides tools for working with YDB's decimal type.
Decimal types are stored as int128 values inside YDB and represented as 16-byte arrays in ydb package and as *math/big.Int in ydb/decimal package.
Note that returned big.Int values are scaled. That is, math operations must be prepared keeping in mind scaling factor:
import ( "ydb/decimal" "math/big" ) var scaleFactor = big.NewInt(10000000000) // Default scale is 9. func main() { x := decimal.FromInt128([16]byte{...}) x.Add(x, big.NewInt(42)) // Incorrect. x.Add(x, scale(42)) // Correct. } func scale(n int64) *big.Int { x := big.NewInt(n) return x.Mul(x, scaleFactor) }
Index ¶
- Variables
- func Append(p []byte, x *big.Int) []byte
- func Err() *big.Int
- func Format(x *big.Int, precision, scale uint32) string
- func FromBytes(bts []byte, precision, scale uint32) *big.Int
- func FromInt128(p [16]byte, precision, scale uint32) *big.Int
- func Inf() *big.Int
- func Int128(x *big.Int, precision, scale uint32) (p [16]byte)
- func IsErr(x *big.Int) bool
- func IsInf(x *big.Int) bool
- func IsNaN(x *big.Int) bool
- func NaN() *big.Int
- func Parse(s string, precision, scale uint32) (*big.Int, error)
- type ParseError
Constants ¶
This section is empty.
Variables ¶
var ErrSyntax = fmt.Errorf("invalid syntax")
Functions ¶
func FromBytes ¶
FromBytes converts bytes representation of decimal to big integer. Most callers should use FromInt128().
If given bytes contains value that is greater than given precision it returns infinity or negative infinity value accordingly the bytes sign.
func FromInt128 ¶
FromInt128 returns big integer from given array. That is, it interprets 16-byte array as 128-bit integer.
Types ¶
type ParseError ¶
func (*ParseError) Error ¶
func (p *ParseError) Error() string
func (*ParseError) Unwrap ¶
func (p *ParseError) Unwrap() error