Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- The Guide To Clipper - <b>strzero() numeric to string with leading zeros examplep.prg</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
StrZero()      Numeric to string with leading zeros    Examplep.prg


Syntax:        StrZero(<expN1> [,<expN2> [,<expN3>]])

Argument:      <expN1> is the numeric value to convert to a
               character string.

               <expN2> is the length of the character string to
               return including decimal digits, decimal point, and minus
               sign.

               <expN3> is the number of decimal places to return.

Returns:       The STR() of <expN1> with leading zeros instead of
               blanks.

Library:       EXTEND.LIB


--------------------------------- Source Code ------------------------------

   FUNCTION StrZero

   PARAMETERS cl_num, cl_len, cl_dec
   PRIVATE cl_str

   DO CASE
   CASE PCOUNT() = 3
      cl_str = STR(cl_num, cl_len, cl_dec)
   CASE PCOUNT() = 2
      cl_str = STR(cl_num,cl_len)
   OTHERWISE
      cl_str = STR(cl_num)
   ENDCASE

   IF "-" $ cl_str
      * Negative number, move the minus sign in front of zeros.
      RETURN "-" + REPLICATE("0", LEN(cl_str) - LEN(LTRIM(cl_str))) +;
                   SUBSTR( cl_str, AT("-", cl_str) + 1)
   ELSE
      * Positive number.
      RETURN REPLICATE("0", LEN(cl_str) - LEN(LTRIM(cl_str))) + LTRIM(cl_str)
   ENDIF


See Also: STR()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson