decimalutil

package
v1.4.55 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 2 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package decimalutil provides utility functions for decimal arithmetic operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatDecimal

func FormatDecimal(d decimal.Decimal, precision int32) string

FormatDecimal 统一格式化输出

Types

type OperationResult

type OperationResult struct {
	Value decimal.Decimal
	Err   error
}

OperationResult 表示运算结果

func Add

func Add(a, b interface{}, precision ...int32) OperationResult

Add 执行加法,支持 string/int/int64/float64 类型,并可指定精度 精度参数必须为非负整数,否则返回错误

func Divide

func Divide(a, b interface{}, precision int32) OperationResult

Divide 执行除法,支持精度设置 精度参数必须为非负整数,否则返回错误

func Multiply

func Multiply(a, b interface{}, precision ...int32) OperationResult

Multiply 执行乘法,支持 string/int/int64/float64 类型,并可指定精度 精度参数必须为非负整数,否则返回错误

func Subtract

func Subtract(a, b interface{}, precision ...int32) OperationResult

Subtract 执行减法,支持 string/int/int64/float64 类型,并可指定精度 精度参数必须为非负整数,否则返回错误

Jump to

Keyboard shortcuts

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