You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
636 B
32 lines
636 B
package godecimal
|
|
|
|
import (
|
|
"math/big"
|
|
)
|
|
|
|
// String 输出 string
|
|
func (d Decimal) String() string {
|
|
return d.floatValue.String()
|
|
}
|
|
|
|
// Float64 输出 float64
|
|
func (d Decimal) Float64() float64 {
|
|
rat, _ := new(big.Rat).SetString(d.String())
|
|
f, _ := rat.Float64()
|
|
return f
|
|
}
|
|
|
|
// MoneyFloat64 货币 float64
|
|
func (d Decimal) MoneyFloat64() float64 {
|
|
rat, _ := new(big.Rat).SetString(d.floatValue.Text('f', 2))
|
|
f, _ := rat.Float64()
|
|
return f
|
|
}
|
|
|
|
// Float64Point 输出 float64带小数点
|
|
func (d Decimal) Float64Point(p int) float64 {
|
|
rat, _ := new(big.Rat).SetString(d.floatValue.Text('f', p))
|
|
f, _ := rat.Float64()
|
|
return f
|
|
}
|