xHarbour Reference Documentation > Function Reference |
Converts a numeric value to a character string, padded with zeros.
StrZero( <nNumber>, [<nLength>], [<nDecimals>] ) --> cString
The function returns <nNumber> formatted as a character string, padded with zeros.
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 value | Length of return string |
---|---|
Field variable | Field length plus decimals |
Expressions/constants | Minimum of 10 digits plus decimals |
Val() | Minimum of 3 digits |
Day() and Month() | 3 digits |
Year() | 5 digits |
Recno() | 7 digits |
See also: | Str(), Transform(), Val() |
Category: | Conversion functions , Character functions |
Source: | rtl\strzero.c |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// 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
http://www.xHarbour.com