1
CREATE FUNCTION cleanAmount(amount DECIMAL)
    RETURNS decimal(30,2)
    LANGUAGE SQL
    DETERMINISTIC
    NO SQL
    SQL SECURITY DEFINER
    COMMENT ''
BEGIN
DECLARE res DECIMAL;
SET res=CAST(COALESCE(amount,0.00) AS DECIMAL(30,2));
RETURN res;
END

SELECT cleanAmount('3.456');返回 3,00。应该是 3,46

4

2 回答 2

3

更改存储过程中 res 的声明:-

CREATE FUNCTION cleanAmount(amount DECIMAL(60,30))
    RETURNS decimal(30,2)
    LANGUAGE SQL
    DETERMINISTIC
    NO SQL
    SQL SECURITY DEFINER
    COMMENT ''
BEGIN
DECLARE res DECIMAL(30,2);
SET res=CAST(COALESCE(amount,0.00) AS DECIMAL(30,2));
RETURN res;
END
于 2013-10-11T10:06:42.620 回答
1

默认小数可能是四舍五入你的数字

DECLARE res DECIMAL(30,2)

于 2013-10-11T10:05:29.373 回答