本文整理匯總了Golang中github.com/pingcap/tidb/mysql.Decimal.Round方法的典型用法代碼示例。如果您正苦於以下問題:Golang Decimal.Round方法的具體用法?Golang Decimal.Round怎麽用?Golang Decimal.Round使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/pingcap/tidb/mysql.Decimal
的用法示例。
在下文中一共展示了Decimal.Round方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: convertToMysqlDecimal
func (d *Datum) convertToMysqlDecimal(target *FieldType) (Datum, error) {
var ret Datum
var dec mysql.Decimal
switch d.k {
case KindInt64:
dec = mysql.NewDecimalFromInt(d.GetInt64(), 0)
case KindUint64:
dec = mysql.NewDecimalFromUint(d.GetUint64(), 0)
case KindFloat32, KindFloat64:
dec = mysql.NewDecimalFromFloat(d.GetFloat64())
case KindString, KindBytes:
var err error
dec, err = mysql.ParseDecimal(d.GetString())
if err != nil {
return ret, errors.Trace(err)
}
case KindMysqlDecimal:
dec = d.GetMysqlDecimal()
case KindMysqlTime:
dec = d.GetMysqlTime().ToNumber()
case KindMysqlDuration:
dec = d.GetMysqlDuration().ToNumber()
case KindMysqlBit:
dec = mysql.NewDecimalFromFloat(d.GetMysqlBit().ToNumber())
case KindMysqlEnum:
dec = mysql.NewDecimalFromFloat(d.GetMysqlEnum().ToNumber())
case KindMysqlHex:
dec = mysql.NewDecimalFromFloat(d.GetMysqlHex().ToNumber())
case KindMysqlSet:
dec = mysql.NewDecimalFromFloat(d.GetMysqlSet().ToNumber())
default:
return invalidConv(d, target.Tp)
}
if target.Decimal != UnspecifiedLength {
dec = dec.Round(int32(target.Decimal))
}
ret.SetValue(dec)
return ret, nil
}