本文整理汇总了Golang中github.com/shopspring/decimal.Decimal.Sub方法的典型用法代码示例。如果您正苦于以下问题:Golang Decimal.Sub方法的具体用法?Golang Decimal.Sub怎么用?Golang Decimal.Sub使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/shopspring/decimal.Decimal
的用法示例。
在下文中一共展示了Decimal.Sub方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例2: Calculate
func (sc *salaryCalculator) Calculate(grossSalary, dependentsQty decimal.Decimal) Salary {
inss := sc.inss.Calculate(grossSalary)
dependents := sc.depedents.Calculate(dependentsQty)
irrfBase := grossSalary.Sub(inss).Sub(dependents)
irrf := sc.irrf.Calculate(irrfBase)
netSalary := grossSalary.Sub(inss).Sub(irrf)
return Salary{
GrossSalary: grossSalary,
INSS: inss,
Dependents: dependents,
IRRF: irrf,
NetSalary: netSalary,
}
}
示例3: newton
func newton(z, x decimal.Decimal) decimal.Decimal {
return z.Sub(z.Mul(z).Sub(x).Div(Const2.Mul(z)))
}