zOs/SQL/FUNNAT

set current sqlid = 'S100447';
-- drop   function A540769.FMTSq2;
create function A540769.fmtSq(n varchar(10), int l) returns varchar(30)
        return case when left(n, 1) = '-' then
                   case when length(n) <= l then
                       '-' || repeat('0', n-length(n)) || substr(n, 2)
                       else   repeat('-', n)
                       end
                   when length(n) <= l then
                       repeat('0', n-length(n)) || n
                   else repeat('+', n)
                  end
;
           || substr(char(r), posstr(char(r), 'E')), 8)
;
with reals (r) as
(
          select  float(0)+0       from sysibm.sysDummy1
    union select  float(123.456)+0 from sysibm.sysDummy1
    union select  float(-23.456)   from sysibm.sysDummy1
    union select  float(-23.456e7)   from sysibm.sysDummy1
    union select  float(-23.456e17)   from sysibm.sysDummy1
    union select  float(-23.456e-6)   from sysibm.sysDummy1
    union select  float(-23.456e-16)   from sysibm.sysDummy1
    union select  float(-10000)/7      from sysibm.sysDummy1
)
select
     r, '<' || char(float(r)) || '>', length(char(r)),
        char(char(
           dec(left(char(r), posstr(char(r), 'E') - 1), 3, 2))
  || '<'   || substr(char(r), posstr(char(r), 'E')), 10) || '>'
     from reals
;
set current sqlid = 's100447';
drop   function A540769.FMT;
create function A540769.FMT(r float) returns char(30)
        return
        char(char(
           dec(left(char(r), posstr(char(r), 'E') - 1), 3, 2))
           || substr(char(r), posstr(char(r), 'E')), 8)
;
select float(0),             float(123.456) from sysibm.sysDummy1;
select a540769.fmt(0), a540769.fmt(123.456e12) from sysibm.sysDummy1;