home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / prgmming / clipper / strzero.prg < prev    next >
Text File  |  1993-10-14  |  2KB  |  85 lines

  1. /*
  2.  * File......: STRZERO.PRG
  3.  * Author....: Martin Colloby
  4.  * BBS.......: The Dark Knight Returns
  5.  * Net/Node..: 050/069
  6.  * User Name.: Martin Colloby
  7.  * Date......: 18/4/93
  8.  * Revision..: 1.0
  9.  *
  10.  * This is an original work by Martin Colloby and is placed in the public
  11.  * domain.
  12.  *
  13.  * Modification history:
  14.  * ---------------------
  15.  *
  16.  * $Log$
  17.  *
  18.  */
  19.  
  20. /*  $DOC$
  21.  *  $FUNCNAME$
  22.  *      GT_STRZERO()
  23.  *  $CATEGORY$
  24.  *      String
  25.  *  $ONELINER$
  26.  *      Convert a numeric to a string padded with leading zeros
  27.  *  $SYNTAX$
  28.  *      GT_StrZero( nNumber , nLength , nDecimals )
  29.  *  $ARGUMENTS$
  30.  *      nNumber   - Number to convert
  31.  *      nLength   - Length of string required - Optional if nDecimals noy used
  32.  *      nDecimals - Number of decimals to simulate - Optional
  33.  *  $RETURNS$
  34.  *      A string padded with zeroes to the left
  35.  *  $DESCRIPTION$
  36.  *      Takes a number and converts it to a string.  If nLength is specified
  37.  *      the string is left padded with zeroes.
  38.  *      If nDecimals is specified, the string will have that many decimal
  39.  *      places
  40.  *  $EXAMPLES$
  41.  *      GT_StrZero( 5 , 2 )       -> "05"
  42.  *      GT_StrZero( 300 , 8 , 2 ) -> "00300.00"
  43.  *  $SEEALSO$
  44.  *
  45.  *  $INCLUDE$
  46.  *
  47.  *  $END$
  48.  */
  49. *
  50. FUNCTION GT_StrZero( nNumber , nLength , nDecimals )
  51.  
  52. /*****************************************************************************
  53.  Purpose - Convert a numeric to a string padded with leading zeros
  54.  Returns - None
  55.  Author  - Martin Colloby
  56.  Created - 05/08/92
  57. ******************************************************************************
  58.  Parameters - None
  59.  Privates   - None
  60.  Locals     - None
  61.  Externals  - None
  62. *****************************************************************************/
  63.  
  64. LOCAL cNumber:= ""
  65.  
  66. DO CASE
  67.     CASE PCOUNT() == 3
  68.         cNumber := STR( nNumber , nLength , nDecimals )
  69.     CASE PCOUNT() == 2
  70.         cNumber := STR( nNumber , nLength )
  71.     CASE PCOUNT() == 1
  72.         cNumber := STR( nNumber )
  73. ENDCASE
  74.  
  75. IF "-" $ cNumber
  76.     // Negative number, move the minus sign in front of zeros
  77.     RETURN "-" + REPLICATE( "0" , LEN( cNumber ) - LEN( LTRIM( cNumber ) ) ) + ;
  78.            SUBSTR( cNumber , AT( "-" , cNumber ) + 1 )
  79. ENDIF
  80.  
  81. // Positive number
  82. RETURN REPLICATE( "0" , LEN( cNumber ) - LEN( LTRIM( cNumber ) ) ) + ;
  83.        LTRIM( cNumber )
  84. *
  85.