本文整理汇总了Golang中github.com/shopspring/decimal.Decimal.Float64方法的典型用法代码示例。如果您正苦于以下问题:Golang Decimal.Float64方法的具体用法?Golang Decimal.Float64怎么用?Golang Decimal.Float64使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/shopspring/decimal.Decimal
的用法示例。
在下文中一共展示了Decimal.Float64方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: toFloat64
//绝对值转成浮点数
func toFloat64(d decimal.Decimal) float64 {
result, ok := d.Float64()
if !ok {
// TODO
}
return result
}
示例2: Decode
//Decode is the inverse operation of Encode.
//Decode returns latitude, longitude, and whether or not they are both represented precisely as float64 types.
func Decode(bucket int64) (float64, float64, bool) {
var latitudeUnshifted, longitudeUnshifted decimal.Decimal
var latitude, longitude float64
var err error
var exact bool
bucketString := strconv.FormatInt(bucket, 10)
for len(bucketString) < 18 {
bucketString = "0" + bucketString
}
latString, lonString := unzip(bucketString)
latString = latString[0:3] + "." + latString[3:]
lonString = lonString[0:3] + "." + lonString[3:]
latitudeUnshifted, err = decimal.NewFromString(latString)
longitudeUnshifted, err = decimal.NewFromString(lonString)
if err != nil {
fmt.Errorf("Error creating decimal from string")
}
latitudeUnshifted = latitudeUnshifted.Sub(decimal.NewFromFloat(90.0))
longitudeUnshifted = longitudeUnshifted.Sub(decimal.NewFromFloat(180.0))
latitude, exact = latitudeUnshifted.Float64()
longitude, exact = longitudeUnshifted.Float64()
return latitude, longitude, exact
}
示例3: DecimalToString
func DecimalToString(res decimal.Decimal, min int32, max int32) string {
if res.Cmp(decimal.New(10, min)) <= 0 || res.Cmp(decimal.New(10, max)) >= 0 {
f, _ := res.Float64()
return strconv.FormatFloat(f, 'G', -1, 64)
}
return res.String()
}
示例4: ConvertToDecimalBinary
func ConvertToDecimalBinary(f func(float64, float64) float64, a decimal.Decimal, b decimal.Decimal) decimal.Decimal {
aFloat, _ := a.Float64()
bFloat, _ := b.Float64()
return decimal.NewFromFloat(f(aFloat, bFloat))
}