decimal

package
v0.17.3 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Float001 = Decimal{/* contains filtered or unexported fields */}
View Source
var One = Decimal{/* contains filtered or unexported fields */}
View Source
var Two = Decimal{/* contains filtered or unexported fields */}
View Source
var Zero = Decimal{/* contains filtered or unexported fields */}

Functions

This section is empty.

Types

type Decimal

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

在govalues.Decimal的基础上包装一层,用于减少error类型的返回

func NewFromFloat64

func NewFromFloat64(e float64) Decimal

func NewFromInt

func NewFromInt(e int) Decimal

func NewFromInt32

func NewFromInt32(e int32) Decimal

func NewFromInt64

func NewFromInt64(e int64) Decimal

func NewFromString

func NewFromString(s string) Decimal

func (Decimal) Abs

func (d Decimal) Abs() Decimal

Abs 取绝对值

func (Decimal) Add

func (d Decimal) Add(e Decimal) Decimal

func (Decimal) AddString

func (d Decimal) AddString(s string) Decimal

func (Decimal) AppendBinary

func (d Decimal) AppendBinary(data []byte) ([]byte, error)

func (Decimal) AppendText

func (d Decimal) AppendText(text []byte) ([]byte, error)

func (Decimal) Ceil

func (d Decimal) Ceil() Decimal

Ceil 返回大于或等于 d 的最近整数值。

func (Decimal) Div

func (d Decimal) Div(e Decimal) Decimal

func (Decimal) Equal

func (d Decimal) Equal(e Decimal) bool

true d = e false other

func (Decimal) Float64

func (d Decimal) Float64() float64

func (Decimal) Floor added in v0.16.10

func (d Decimal) Floor() Decimal

Floor 返回小于或等于 d 的最近整数值。

func (Decimal) Greater

func (d Decimal) Greater(e Decimal) bool

true d > e false other

func (Decimal) GreaterEqual

func (d Decimal) GreaterEqual(e Decimal) bool

true d >= e false other

func (Decimal) IntPart

func (d Decimal) IntPart() int64

只取整数部份

func (Decimal) IsNeg

func (d Decimal) IsNeg() bool

IsNeg 是否为负数

true  if d < 0
false otherwise

func (Decimal) IsPositive

func (d Decimal) IsPositive() bool

IsPositive 是否正数 true if d > 0 false otherwise

func (Decimal) IsZero

func (d Decimal) IsZero() bool

func (Decimal) Less

func (d Decimal) Less(e Decimal) bool

true d < e false other

func (Decimal) LessEqual

func (d Decimal) LessEqual(e Decimal) bool

true d <= e false other

func (Decimal) MarshalBSONValue

func (d Decimal) MarshalBSONValue() (typ byte, data []byte, err error)

func (Decimal) MarshalBinary

func (d Decimal) MarshalBinary() ([]byte, error)

func (Decimal) MarshalJSON

func (d Decimal) MarshalJSON() ([]byte, error)

func (Decimal) MarshalText

func (d Decimal) MarshalText() ([]byte, error)

func (Decimal) Mul

func (d Decimal) Mul(e Decimal) Decimal

func (Decimal) MulFloat001

func (d Decimal) MulFloat001() Decimal

func (Decimal) Neg

func (d Decimal) Neg() Decimal

取反数

func (Decimal) Round

func (d Decimal) Round(scale int) Decimal

四舍五入

func (*Decimal) Scan

func (d *Decimal) Scan(value any) error

func (Decimal) String

func (d Decimal) String() string

func (Decimal) StringFixed

func (d Decimal) StringFixed(pointStatCoinsPoint int) string

StringFixed 四舍五入

Example:

NewFromFloat(0).StringFixed(2) // output: "0.00"
NewFromFloat(0).StringFixed(0) // output: "0"
NewFromFloat(5.45).StringFixed(0) // output: "5"
NewFromFloat(5.45).StringFixed(1) // output: "5.5"
NewFromFloat(5.45).StringFixed(2) // output: "5.45"
NewFromFloat(5.45).StringFixed(3) // output: "5.450"
NewFromFloat(545).StringFixed(-1) // output: "550"

func (Decimal) Sub

func (d Decimal) Sub(e Decimal) Decimal

func (Decimal) Truncate

func (d Decimal) Truncate() Decimal

Truncate 舍去小数部份

func (*Decimal) UnmarshalBSONValue

func (d *Decimal) UnmarshalBSONValue(typ byte, data []byte) error

func (*Decimal) UnmarshalBinary

func (d *Decimal) UnmarshalBinary(data []byte) error

func (*Decimal) UnmarshalJSON

func (d *Decimal) UnmarshalJSON(data []byte) error

func (*Decimal) UnmarshalText

func (d *Decimal) UnmarshalText(text []byte) error

func (Decimal) Value

func (d Decimal) Value() (driver.Value, error)

Jump to

Keyboard shortcuts

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