godecimal

package module
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2023 License: MIT Imports: 5 Imported by: 3

README

Golang Decimal

📦 Golang 小数点处理

godoc goproxy.cn goreportcard.com deps.dev

安装

go get -v -u go.dtapp.net/godecimal@v1.0.11

使用

package main

import (
	"go.dtapp.net/godecimal"
	"log"
	"reflect"
)

func main() {
	log.Println("加:", godecimal.Float64Add(10, 3), reflect.TypeOf(godecimal.Float64Add(10, 3)))
	log.Println("减", godecimal.Float64Sub(10, 3), reflect.TypeOf(godecimal.Float64Sub(10, 3)))
	log.Println("乘:", godecimal.Float64Mul(10, 3), reflect.TypeOf(godecimal.Float64Mul(10, 3)))
	log.Println("除:", godecimal.Float64Quo(10, 3), reflect.TypeOf(godecimal.Float64Quo(10, 3)))
}

Documentation

Index

Constants

View Source
const Version = "1.0.11"

Variables

This section is empty.

Functions

func Abs

func Abs(x float64) float64

Abs 取绝对值

func Ceil

func Ceil(x float64) float64

Ceil 向上取整

func Float64Add

func Float64Add(f1, f2 float64) float64

Float64Add 加 (f1+f2)

func Float64Mul

func Float64Mul(f1, f2 float64) float64

Float64Mul 乘 (f1*f2)

func Float64Quo

func Float64Quo(f1, f2 float64) float64

Float64Quo 除 (f1/f2)

func Float64Sub

func Float64Sub(f1, f2 float64) float64

Float64Sub 减 (f1-f2)

func Floor

func Floor(x float64) float64

Floor 向下取整

func Max

func Max(x, y float64) float64

Max 取较大值

func Min

func Min(x, y float64) float64

Min 取较小值

func Round

func Round(x float64) float64

Round 就近取整

func RoundPoint

func RoundPoint(x float64) float64

RoundPoint 就近取整并保留小数点

Types

type DFloat added in v1.0.11

type DFloat struct {
	FValue float64
	Point  int
}

func (*DFloat) Scan added in v1.0.11

func (f *DFloat) Scan(value interface{}) error

Scan 方法实现了 sql.Scanner 接口

func (DFloat) Value added in v1.0.11

func (f DFloat) Value() (driver.Value, error)

Value 实现 driver.Valuer 接口,Value 返回 json value

type Decimal

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

func New

func New() Decimal

func NewFloat

func NewFloat(f float64) Decimal

NewFloat 从浮点数创建

func NewInt

func NewInt(i int64) Decimal

NewInt 从整数创建

func NewInterface added in v1.0.11

func NewInterface(value interface{}) Decimal

NewInterface 创建

func NewString

func NewString(s string) Decimal

NewString 从字符串创建

func NewUint

func NewUint(i uint64) Decimal

NewUint 从无符合整数创建

func (Decimal) Add

func (d Decimal) Add(d2 Decimal) Decimal

Add 加 (d+d2)

func (Decimal) AddFloat added in v1.0.5

func (d Decimal) AddFloat(d2 float64) Decimal

AddFloat 加

func (Decimal) AddInt added in v1.0.5

func (d Decimal) AddInt(d2 int64) Decimal

AddInt 加

func (Decimal) AddString added in v1.0.5

func (d Decimal) AddString(d2 string) Decimal

AddString 加

func (Decimal) Float64

func (d Decimal) Float64() float64

Float64 输出 float64

func (Decimal) Float64Point added in v1.0.6

func (d Decimal) Float64Point(p int) float64

Float64Point 输出float64带小数点

func (Decimal) Float64PointAdaptive added in v1.0.7

func (d Decimal) Float64PointAdaptive(maxP int) float64

Float64PointAdaptive 输出float64带小数点(自适应)

func (Decimal) Int64 added in v1.0.9

func (d Decimal) Int64() int64

Int64 输出 int64

func (Decimal) IsInteger added in v1.0.8

func (d Decimal) IsInteger(d2 float64) bool

IsInteger 是否为整数

func (Decimal) MoneyFloat64

func (d Decimal) MoneyFloat64() float64

MoneyFloat64 货币 float64

func (Decimal) Mul

func (d Decimal) Mul(d2 Decimal) Decimal

Mul 乘 (d*d2)

func (Decimal) MulFloat added in v1.0.5

func (d Decimal) MulFloat(d2 float64) Decimal

MulFloat 乘

func (Decimal) MulInt added in v1.0.5

func (d Decimal) MulInt(d2 int64) Decimal

MulInt 乘

func (Decimal) MulString added in v1.0.5

func (d Decimal) MulString(d2 string) Decimal

MulString 乘

func (Decimal) Quo

func (d Decimal) Quo(d2 Decimal) Decimal

Quo 除 (d/d2)

func (Decimal) QuoFloat added in v1.0.5

func (d Decimal) QuoFloat(d2 float64) Decimal

QuoFloat 除

func (Decimal) QuoInt added in v1.0.5

func (d Decimal) QuoInt(d2 int64) Decimal

QuoInt 除

func (Decimal) QuoString added in v1.0.5

func (d Decimal) QuoString(d2 string) Decimal

QuoString 除

func (Decimal) String

func (d Decimal) String() string

String 输出 string

func (Decimal) Sub

func (d Decimal) Sub(d2 Decimal) Decimal

Sub 减 (d-d2)

func (Decimal) SubFloat added in v1.0.5

func (d Decimal) SubFloat(d2 float64) Decimal

SubFloat 减

func (Decimal) SubInt added in v1.0.5

func (d Decimal) SubInt(d2 int64) Decimal

SubInt 减

func (Decimal) SubString added in v1.0.5

func (d Decimal) SubString(d2 string) Decimal

SubString 减

Jump to

Keyboard shortcuts

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