gofpdecimal

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2023 License: MIT Imports: 2 Imported by: 0

README

go-fpdecimal

a very simple fixed-point decimal library which only supports conversion to/from string and float. The capacity is limited and no arithmetic operation is supported. This is only a toy project and the functionality is enough for me.

Codes are mainly copied from fpdecimal. I change ParseFixedPointDecimal so that the precision is inferer from the string itself.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendFixedPointDecimal

func AppendFixedPointDecimal(b []byte, v int64, p int) []byte

AppendFixedPointDecimal appends formatted fixed point decimal to destination buffer. Returns appended slice. This is efficient for avoiding memory copy. strconv.AppendInt is very efficient. Efficient converting int64 to ASCII is not as trivial.

func FixedPointDecimalToString

func FixedPointDecimalToString(v int64, p int) string

FixedPointDecimalToString formats fixed-point decimal to string

func ParseFixedPointDecimal

func ParseFixedPointDecimal(s string) (int64, uint, error)

Types

type FpDecimal

type FpDecimal struct {
	// contains filtered or unexported fields
}

func FromFloat64

func FromFloat64(f float64, precision uint) FpDecimal

func FromInteger

func FromInteger(i int64) FpDecimal

func FromString

func FromString(s string) (FpDecimal, error)

func GetOne

func GetOne() FpDecimal

func GetZero

func GetZero() FpDecimal

func NewFpDecimal

func NewFpDecimal(precision uint) FpDecimal

func (*FpDecimal) Float32

func (d *FpDecimal) Float32() float32

func (*FpDecimal) Float64

func (d *FpDecimal) Float64() float64

func (*FpDecimal) GetPrecision

func (d *FpDecimal) GetPrecision() uint

func (*FpDecimal) MarshalJSON

func (d *FpDecimal) MarshalJSON() ([]byte, error)

func (*FpDecimal) String

func (d *FpDecimal) String() string

func (*FpDecimal) UnmarshalJSON

func (d *FpDecimal) UnmarshalJSON(b []byte) (err error)

Jump to

Keyboard shortcuts

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