Format Specifiers in WPSML
Format Specifiers in WPSML
Chris Hector
Logictran, Inc.
Version 1.0
October 19, 2005
Introduction
WPSML algorithmic and plotting capabilities require the ability to control the presentation of computed variables. For example, a variable with a computed value of 1.5 may need to be presented as a whole number (1), a decimal (1.5), currency ($1.50), or a fraction ([pic]). The WPSML 2.0 specification described a simple capability to specify this formatting. This document extends that definition and provides more details and examples.
Variable Element Format Attribute
The variable element supports a format attribute. If this attribute is omitted, the system can use a default rendering of the variable. This default rendering is not defined by the specification but should be designed to provide reasonable rendering for any value presented.
The format attribute is a string that specifies the type of output, digits of precision, padding, sign and other formatting characteristics. For example, to specify that variable x should be formatted as an integer, you would write:
.
|# |Integer format. |
| |Expands to as many digits as required to output the integer. |
| |If more than one "#" appears, leading spaces will be used to pad the output to same number |
| |of positions. |
| |Negative values are prefixed with a minus sign in the leftmost position of the output. |
|(#) |Parenthesis around either integer or floating point indicate that negative values are |
| |rendered with parenthesis rather than a minus sign. |
|#.# |Floating point with 1 digits of precision. |
| |Additional digits of precision are added by providing more "#" to the right of the decimal |
| |point. Integer portion expands to as many digits as required. |
| |If more than one "#" appears on the left of the decimal, leading spaces will be used to pad |
| |the output to same number of positions. |
| |A "#" is not required on the left of the decimal point. |
| |Negative values are prefixed with a minus sign in the leftmost position of the output. |
|0 |A zero acts the same as "#" except that zero padding is used instead of space padding. |
|+ |A plus sign forces positive numbers to have a leading plus sign. Negative numbers will have |
| |a minus sign in the same position. |
|#.#E+0 |scientific notation with 1 digits of precision and one digit for the exponent. Additional |
| |digits of exponent are added by providing more "0" to the right of the plus. |
| |Additional digits of precision are added by providing more "#" to the right of the decimal |
| |point. Integer portion expands to as many digits as required. |
| |If more than one "#" appears on the left of the decimal, leading spaces will be used to pad |
| |the output to same number of positions. |
| |A "#" is not required on the left of the decimal point. |
| |Negative values are prefixed with a minus sign in the leftmost position of the output. |
|# #/# |Mixed fraction with one digit of precision for each of the whole number, numerator and |
| |denominator. Additional "#" or "0"'s can be used to adjust padding. The fraction is always |
| |reduced to lowest terms. |
|#/# |Fraction with one digit of precision for the numerator and denominator. Additional "#" or |
| |"0"'s can be used to adjust padding. The fraction is always reduced to lowest terms. |
|$ |A dollar sign forces a currency sign at the start of the number. |
|, |A comma indicates that the integer portion of the number will be output in groups of three |
| |digits with a comma separating the groups. |
|R# |The R indicates an n'th root (default radix is 2). Note that overriding the radix requires a|
| |second input to the formatting process. The second input is provided with the p2 attribute |
| |of the variable element. |
|#R# |A # preceding the R indicates an reduced n'th root (default radix is 2). Note that |
| |overriding the radix requires a second input to the formatting process. The second input is |
| |provided with the p2 attribute of the variable element. |
Examples:
The variables used in these examples have the following values:
|Name |Type |Value |
|v9 |int |9 |
|v2 |int |2 |
|v3 |int |3 |
|vn9 |int |-9 |
|v27 |int |27 |
The contents of the variable element show the formatted results given the above values.
R formatting
|Number |Example |
|1 |format_radical(9, 2, FALSE) = [pic] |
| | |
| | |
| | |
| |9 |
| | |
| | |
| | |
|2 |format_radical(9, 2, TRUE) = 3 |
| |3 |
|3 |format_radical(9, 3, FALSE) = [pic] |
| | |
| | |
| | |
| |9 |
| | |
| | |
| |3 |
| | |
| | |
| | |
|4 |format_radical(-9, 2, FALSE) = [pic] |
| | |
| | |
| | |
| |-9 |
| | |
| | |
| | |
|5 |format_radical(9, 3, TRUE) = [pic] |
| | |
| | |
| | |
| |9 |
| | |
| | |
| |3 |
| | |
| | |
| | |
|6 |format_radical(-9, 2, FALSE) = [pic] |
| | |
| | |
| | |
| |-9 |
| | |
| | |
| | |
|7 |format_radical(-9, 3, FALSE) = [pic] |
| | |
| | |
| | |
| |-9 |
| | |
| | |
| |3 |
| | |
| | |
| | |
|8 |format_radical(-9, 3, TRUE) = -[pic] |
| |- |
| | |
| | |
| |9 |
| | |
| | |
| |3 |
| | |
| | |
| | |
|9 |format_radical(27, 2, FALSE) = [pic] |
| | |
| | |
| | |
| |27 |
| | |
| | |
| | |
|10 |format_radical(27, 2, TRUE) = 3[pic] |
| |3 |
| | |
| | |
| |27 |
| | |
| | |
| | |
|11 |format_radical(27, 3, FALSE) = [pic] |
| | |
| | |
| | |
| |27 |
| | |
| | |
| |3 |
| | |
| | |
| | |
|12 |format_radical(27, 3, TRUE) = 3 |
| |3 |
|13 |format_radical(-9, 2, TRUE) = 3i |
| |3i |
|14 |format_radical(-27, 2, FALSE) = [pic] |
| | |
| | |
| | |
| |-27 |
| | |
| | |
| | |
|15 |format_radical(-27, 2, TRUE) = 3i[pic] |
| |3i |
| | |
| | |
| |-9 |
| | |
| | |
| | |
|16 |format_radical(-27, 3, FALSE) = [pic] |
| | |
| | |
| | |
| |-27 |
| | |
| | |
| |3 |
| | |
| | |
| | |
|17 |format_radical(-27, 3, TRUE) = -3 |
| |-3 |
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
Related searches
- apa format for in text citation
- apa format fill in template
- mla format for in text citation
- excel format percent in formula
- printf format specifiers in c
- printf format specifiers java
- format class in java
- format datetime in javascript
- format number in r
- mla format citing in essay
- format tables in tableau
- format time in javascript