xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

StrZero()

Converts a numeric value to a character string, padded with zeros.

Syntax

StrZero( <nNumber>, [<nLength>], [<nDecimals>] ) --> cString

Arguments

<nNumber>
A numeric value to convert to a character string.
<nLength>
An optional numeric value specifying the length of the return string, including sign and decimal places.
<nDecimals>
This is an optional numeric value indicating the number of decimal places to return.

Return

The function returns <nNumber> formatted as a character string, padded with zeros.

Description

StrZero() converts a numeric value to a character string. This is required when numeric values must be concatenated with character strings for formatted display, or when index keys containing Numeric and Character fields must be created.

If the length of the return string is specified too small, so that Int(<nNumber>) does not fit into the result, StrZero() returns a string filled with asterisks (*).

If only decimal places do not fit entirely, StrZero() rounds <nNumber> to the requested decimal places.

If both, <nLength> and <nDecimals>, are not specified, StrZero() obtains default values for both optional parameters as follows:

Formatting rules of StrZero()
Numeric valueLength of return string
Field variableField length plus decimals
Expressions/constantsMinimum of 10 digits plus decimals
Val()Minimum of 3 digits
Day() and Month()3 digits
Year()5 digits
Recno()7 digits

Info

See also:Str(), Transform(), Val()
Category: Conversion functions , Character functions
Source:rtl\strzero.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example demonstrates formatting rules applied by StrZero()

   PROCEDURE Main
      LOCAL  nValue := 123.456

      ? StrZero( nValue )              // result: 0000000123.456

      ? StrZero( nValue, 1 )           // result: *
      ? StrZero( nValue, 2 )           // result: **
      ? StrZero( nValue, 3 )           // result: 123
      ? StrZero( nValue, 4 )           // result: 0123
      ? StrZero( nValue, 5 )           // result: 00123

      ? StrZero( nValue, 5, 1 )        // result: 123.5
      ? StrZero( nValue, 6, 2 )        // result: 123.46
      ? StrZero( nValue, 7, 3 )        // result: 123.456
      ? StrZero( nValue, 8, 4 )        // result: 123.4560

      nValue := - 123.456
      ? StrZero( nValue, 10, 0 )       // result: -000000123
      ? StrZero( nValue, 10, 1 )       // result: -0000123.5
      ? StrZero( nValue, 10, 2 )       // result: -000123.46
      ? StrZero( nValue, 10, 3 )       // result: -00123.456
      ? StrZero( nValue, 10, 4 )       // result: -0123.4560
   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe