Difference between revisions of "PRINTF()"
From Recital Documentation Wiki
Yvonnemilne (Talk | contribs) |
Yvonnemilne (Talk | contribs) |
||
Line 39: | Line 39: | ||
==Example== | ==Example== | ||
<code lang="recital"> | <code lang="recital"> | ||
− | + | // When %s is specified, the corresponding argument is converted to | |
− | + | // character format (similar to specifying etos()). | |
− | + | // Widths correspond to the default values, e.g. numerics are 10 | |
− | + | printf('It is %s, %s to be more precise\n',year(date()),datetime()) | |
− | + | printf('The value of pi is %s\n',pi()) | |
− | + | printf('They cost %s per %-s\n',$99,100) | |
+ | printf('Logicals can be %s or %s\n',.T.,.F.) | ||
+ | // Formatting characters can contain a width, which will left pad with spaces | ||
+ | printf('Right-justify and pad left: %10s this\n','Like') | ||
+ | // Left justify by placing a '-' directly following the '%' character | ||
+ | printf('Left-justify and pad right: %-10s this\n','Like') | ||
+ | // %d is for numerics | ||
+ | printf('It is %d\n',year(date())) | ||
+ | // %t and %T are for formating datetime data types. | ||
+ | printf('It is %d, %t to be more precise\n',year(date()),datetime()) | ||
+ | printf('It is %d, %T to be even more precise\n',year(date()),datetime()) | ||
+ | // %f is for floating point numerics | ||
+ | printf('The value of pi is %f\n',pi()) | ||
+ | // Decimal places can also be specified for numerics (%d, %f) | ||
+ | printf('The value of pi to two decimal places is %4.2f\n',pi()) | ||
+ | // %y is for formatting currency data types | ||
+ | printf('They cost %y per %d\n',$99,100) | ||
+ | printf('They cost %y per %d\n',$99,1000) | ||
+ | printf('They cost %y per %d\n',$99,10000) | ||
+ | //%l and %L are for formatting logical datatypes. | ||
+ | printf('Logicals can be %l or %l\n',.T.,.F.) | ||
+ | printf('Logicals can also be %L or %L\n',.T.,.F.) | ||
</code> | </code> | ||
Revision as of 12:23, 11 November 2009
Purpose
Function to perform 'C' style picture formatting
Syntax
PRINTF(<expC>, <exp1> [,<exp2>...])
See Also
ETOS(), FPRINTF(), SPRINTF(), TOSTRING()
Description
The PRINTF() function displays a string including one or more parameters, <exp1> [,<exp2>...], formatted according to the 'C' style options specified in <expC>. Each formatting sequence is applied to the corresponding parameter in the parameter list from left to right.
Formatting option | Description |
---|---|
%s | |
%d | |
%f | |
%y | |
%t | |
%T | |
%l | |
%L |
Example
// When %s is specified, the corresponding argument is converted to // character format (similar to specifying etos()). // Widths correspond to the default values, e.g. numerics are 10 printf('It is %s, %s to be more precise\n',year(date()),datetime()) printf('The value of pi is %s\n',pi()) printf('They cost %s per %-s\n',$99,100) printf('Logicals can be %s or %s\n',.T.,.F.) // Formatting characters can contain a width, which will left pad with spaces printf('Right-justify and pad left: %10s this\n','Like') // Left justify by placing a '-' directly following the '%' character printf('Left-justify and pad right: %-10s this\n','Like') // %d is for numerics printf('It is %d\n',year(date())) // %t and %T are for formating datetime data types. printf('It is %d, %t to be more precise\n',year(date()),datetime()) printf('It is %d, %T to be even more precise\n',year(date()),datetime()) // %f is for floating point numerics printf('The value of pi is %f\n',pi()) // Decimal places can also be specified for numerics (%d, %f) printf('The value of pi to two decimal places is %4.2f\n',pi()) // %y is for formatting currency data types printf('They cost %y per %d\n',$99,100) printf('They cost %y per %d\n',$99,1000) printf('They cost %y per %d\n',$99,10000) //%l and %L are for formatting logical datatypes. printf('Logicals can be %l or %l\n',.T.,.F.) printf('Logicals can also be %L or %L\n',.T.,.F.)
Products
Recital Database Server, Recital Mirage Server, Recital Terminal Developer