Example #1
0
// See: http://dev.mysql.com/doc/refman/5.7/en/mathematical-functions.html#function_round
func builtinRound(args []types.Datum, _ context.Context) (d types.Datum, err error) {
	x, err := args[0].ToFloat64()
	if err != nil {
		return d, errors.Trace(err)
	}

	dec := 0
	if len(args) == 2 {
		y, err1 := args[1].ToInt64()
		if err1 != nil {
			return d, errors.Trace(err1)
		}
		dec = int(y)
	}
	d.SetFloat64(types.Round(x, dec))
	return d, nil
}
Example #2
0
// See http://dev.mysql.com/doc/refman/5.7/en/mathematical-functions.html#function_round
func builtinRound(args []types.Datum, ctx context.Context) (d types.Datum, err error) {
	sc := ctx.GetSessionVars().StmtCtx
	x, err := args[0].ToFloat64(sc)
	if err != nil {
		return d, errors.Trace(err)
	}

	dec := 0
	if len(args) == 2 {
		y, err1 := args[1].ToInt64(sc)
		if err1 != nil {
			return d, errors.Trace(err1)
		}
		dec = int(y)
	}
	d.SetFloat64(types.Round(x, dec))
	return d, nil
}