本文整理汇总了Golang中github.com/pingcap/tidb/mysql.MyDecimal.FromUint方法的典型用法代码示例。如果您正苦于以下问题:Golang MyDecimal.FromUint方法的具体用法?Golang MyDecimal.FromUint怎么用?Golang MyDecimal.FromUint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/pingcap/tidb/mysql.MyDecimal
的用法示例。
在下文中一共展示了MyDecimal.FromUint方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ConvertDatumToDecimal
// ConvertDatumToDecimal converts datum to decimal.
func ConvertDatumToDecimal(d Datum) (*mysql.MyDecimal, error) {
dec := new(mysql.MyDecimal)
var err error
switch d.Kind() {
case KindInt64:
dec.FromInt(d.GetInt64())
case KindUint64:
dec.FromUint(d.GetUint64())
case KindFloat32:
err = dec.FromFloat64(float64(d.GetFloat32()))
case KindFloat64:
err = dec.FromFloat64(d.GetFloat64())
case KindString:
err = dec.FromString(d.GetBytes())
case KindMysqlDecimal:
*dec = *d.GetMysqlDecimal()
case KindMysqlHex:
dec.FromInt(d.GetMysqlHex().Value)
case KindMysqlBit:
dec.FromUint(d.GetMysqlBit().Value)
case KindMysqlEnum:
dec.FromUint(d.GetMysqlEnum().Value)
case KindMysqlSet:
dec.FromUint(d.GetMysqlSet().Value)
default:
err = fmt.Errorf("can't convert %v to decimal", d.GetValue())
}
return dec, err
}
示例2: evalAggAvg
func (e *Evaluator) evalAggAvg(v *ast.AggregateFuncExpr) {
ctx := v.GetContext()
switch ctx.Value.Kind() {
case types.KindFloat64:
t := ctx.Value.GetFloat64() / float64(ctx.Count)
v.SetValue(t)
case types.KindMysqlDecimal:
x := ctx.Value.GetMysqlDecimal()
var y, to mysql.MyDecimal
y.FromUint(uint64(ctx.Count))
mysql.DecimalDiv(x, &y, &to, mysql.DivFracIncr)
to.Round(&to, ctx.Value.Frac()+mysql.DivFracIncr)
v.SetMysqlDecimal(&to)
}
ctx.Value = *v.GetDatum()
}