Documentation
¶
Overview ¶
Package numberutil numberutil 包用于封装数值类型的辅助函数
Index ¶
- func EqualFloat32Prec(x, y float32, decimals int) bool
- func EqualFloat64(x, y, limit float64) bool
- func EqualFloat64Prec(x, y float64, decimals int) bool
- func IntFromFloat64(x float64) (int, error)
- func NumberStr(n int64, sep rune) string
- func Round(x float64, n int) float64
- func Uint8FromInt(x int) (uint8, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EqualFloat32Prec ¶
EqualFloat32Prec 在给定精度范围内比较两个 float32 是否相等 decimals 表示小数点后精度的位数 note: 效率比 EqualFloat64 差
func EqualFloat64 ¶
EqualFloat64 在给定精度范围内比较两个 float64 是否相等 if limit < 0,则精度设置为机器所能达到的最大精度 if x 和 y 的两个近似值的差小于limit,则判定x,y是相等的
Example ¶
type args struct {
x float64
y float64
}
data := []args{
{0.2, 0.2},
}
for _, v := range data {
fmt.Printf("%-5t, %-5t, %-5t, ", v.x == v.y, EqualFloat64(v.x, v.y, -1), EqualFloat64(v.x, v.y, 0.000000000001))
fmt.Println(v.x, v.y)
}
// 输出结果如下:
// true true true 0.2 0.2
// false false false 0.6 0.61
// false false true 0.799 0.8
func EqualFloat64Prec ¶
EqualFloat64Prec 在给定精度范围内比较两个 float64 是否相等 decimals 表示小数点后精度的位数 note: 效率比 EqualFloat64 差
func IntFromFloat64 ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.