Task

Express a number in decimal as a fixed-length string with leading zeros.



For example, the number   7.125   could be expressed as   00007.125.




PROC newRealF(es, fl, digit, len=0, zeros=TRUE)
  DEF s, t, i
  IF (len = 0) OR (len < (digit+3))
    RETURN RealF(es, fl, digit)
  ELSE
    s := String(len)
    t := RealF(es, fl, digit)
    FOR i := 0 TO len-EstrLen(t)-1 DO StrAdd(s, IF zeros THEN '0' ELSE ' ')
    StrAdd(s, t)
    StrCopy(es, s)
    DisposeLink(s)
    DisposeLink(t)
  ENDIF
ENDPROC es
 
PROC main()
  DEF s[100] : STRING
  WriteF('\s\n', newRealF(s, 7.125, 3,9))
ENDPROC