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
答案 0 :(得分: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
答案 1 :(得分:1)
默认小数可能是你的数字四舍五入
DECLARE res DECIMAL(30,2)