home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Database / CLIPR503.W96 / STRZERO.PR_ / STRZERO.PR
Text File  |  1995-06-20  |  986b  |  48 lines

  1. /***
  2. *
  3. *  Strzero.prg
  4. *
  5. *  Summer '87 STRZERO() Compatibility Routine
  6. *
  7. *  Copyright (c) 1993, Computer Associates International Inc.
  8. *  All rights reserved.
  9. *
  10. */
  11.  
  12.  
  13. /***
  14. *
  15. *   StrZero( <nNumber>, <nLength>, <nDecimals> ) --> cNumber
  16. *
  17. *   Convert a numeric to a string padded with leading zeros
  18. *
  19. */
  20. FUNCTION StrZero( n, nLength, nDecimals )
  21.  
  22.    LOCAL cNumber
  23.  
  24.    IF PCOUNT() == 3
  25.       cNumber := STR( n, nLength, nDecimals )
  26.  
  27.    ELSEIF PCOUNT() == 2
  28.       cNumber := STR( n, nLength )
  29.  
  30.    ELSE
  31.       cNumber := STR( n )
  32.  
  33.    ENDIF
  34.  
  35.    IF "-" $ cNumber
  36.       
  37.       // Negative number, move the minus sign in front of zeros
  38.       RETURN ( "-" + REPLICATE( "0", LEN( cNumber ) -    ;
  39.                LEN( LTRIM( cNumber ))) +                 ;
  40.                SUBSTR( cNumber, AT( "-", cNumber ) + 1 ) )
  41.  
  42.    ENDIF
  43.  
  44.    // Positive number
  45.    RETURN ( REPLICATE( "0", LEN( cNumber ) - LEN( LTRIM( cNumber ))) + ;
  46.             LTRIM( cNumber ) )
  47.  
  48.