pears.CommaThousandsDec

Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace.

CREATE FUNCTION "pears"."CommaThousandsDec"( 
  /* Application Maintained Function / Procedure - DO NOT EDIT*/
  IN "d" DOUBLE ) 
RETURNS CHAR(40)
BEGIN
  DECLARE "rv" CHAR(40);
  DECLARE "s" CHAR(20);
  DECLARE "t" CHAR(20);
  DECLARE "i" INTEGER;
  DECLARE "c" CHAR(1);
  DECLARE "fract" DOUBLE;
  SET "fract" = "abs"("remainder"("d",1));
  IF "fract" = 0 THEN SET "fract" = NULL
  END IF;
  IF "d" IS NULL THEN
    RETURN NULL
  END IF;
  IF "d" < 0 THEN
    SET "d" = "abs"("d");
    SET "c" = '-'
  ELSE
    SET "c" = ''
  END IF;
  SET "rv" = '';
  SET "s" = "trim"("str"("d",20,0));
  SET "i" = -1;
  "lbl": loop
    SET "t" = "substr"("s","i",-3);
    IF "t" = '' THEN
      leave "lbl"
    END IF;
    IF "rv" <> '' THEN
      SET "rv" = ','+"rv"
    END IF;
    SET "rv" = "t"+"rv";
    SET "i" = "i"-3
  END loop "lbl";
  RETURN("c"+"rv"+"string"("fract"))
END
  • database/functions/pears_commathousandsdec.txt
  • Last modified: 2026/08/07 19:24
  • by 127.0.0.1