GoLang 第三方库 decimal

时间:2025-03-16 08:34:16

,float,double

golang 使用了 IEEE-754 标准存储浮点数,大多数小数表示成二进制之后是近似且无限的。float 转换为 decimal 类型时,并不需要像 python 一样通过 string 中转,也依然可以保持精度。对于钱,在结构体字段中,我们完全可以直接使用 float 类型,并不需要用 string 类型。

关于 go 中 decimal 包详解:Golang 笔记之深入浮点数 - 知乎

2.载入 decimal 包

go 中 decimal 使用第三方库: /shopspring/decimal

go get  /shopspring/decimal