I need to convert a Double to String and format it with thousand separator and 2 decimal place. I have done the conversion of Double to String in a function. But stuck at formatting the String. Is there any clean way to format the String? I am still using DB2 9.5 so VARCHAR_FORMAT() might not be an option for me.
CREATE FUNCTION BELSIZE.DBL2STR_2DP (VAR0 DOUBLE)
RETURNS VARCHAR(50)
F1: BEGIN ATOMIC
DECLARE var0_2dp DOUBLE;
DECLARE sVar VARCHAR(50);
DECLARE dec_part VARCHAR(50);
SET var0_2dp = ROUND(VAR0, 2);
SET sVar = CAST(CHAR(ABS(DECIMAL(var0_2dp, 31, 2))) AS VARCHAR(50));
SET sVar = STRIP(sVar, LEADING, '0');
IF VAR0 < 0 THEN
SET sVar = CONCAT('-', sVar);
END IF;
RETURN sVar;
END