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,46Mysql存儲函數返回錯誤值
試試'ROUND'而不是'CAST'?例如:'ROUND(3.456.2)' – InSane
'SET res = ROUND(amount,2);'返回3,00。 'SELECT CAST(COALESCE(3.456,0.00)AS DECIMAL(30,2))'返回3.46:s –
即使將該行更改爲SET res = amount;返回3.00 – Kickstart