The Format function provides 'C' like formatting of simple data types into a string. It provides very precise control over this formatting. The Formatting parameter defines how the value is manipulated into the returned string.
NOTE: By default the resulting content and the content of the parameter “Format”, “DecimalSeparator”, “ThousandSeparator” will be parsed (all <#..> tags will be evaluated) before to apply this filter. You can control this behavior throught the parameter AnalyzeTagParams
The Formatting string can comprise a mix of ordinary characters (that are passed unchanged to the result string), and data formatting characters. This formatting is best explained by the example code. Ordinary characters must be quoted and data formatting characters must be one of the following :
| Boolean | The argument must be an integer or boolean value. The value is converted to a boolean string using the TrueStr and FalseStr params. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Decimal | The argument must be an integer value. The value is converted to a string of decimal digits. If the format string contains a precision specifier, it indicates that the resulting string must contain at least the specified number of digits; if the value has less digits, the resulting string is left-padded with zeros. A width specifier sets the minimum field width for a conversion. If the resulting string is shorter than the minimum field width, it is padded with blanks to increase the field width. The default is to right-justify the result by adding blanks in front of the value, but if the format specifier contains a left-justification indicator (an ”-” en dash character preceding the width specifier), the result is left-justified by adding blanks after the value. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Unsigned decimal | Similar to d, but no sign is output. A width specifier sets the minimum field width for a conversion. If the resulting string is shorter than the minimum field width, it is padded with blanks to increase the field width. The default is to right-justify the result by adding blanks in front of the value, but if the format specifier contains a left-justification indicator (an ”-” en dash character preceding the width specifier), the result is left-justified by adding blanks after the value. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Scientific | The argument must be a floating-point value. The value is converted to a string of the form ”-d.ddd…E+ddd”. The resulting string starts with a minus sign if the number is negative. One digit always precedes the decimal point. The total number of digits in the resulting string (including the one before the decimal point) is given by the precision specifier in the format string; a default precision of 15 is assumed if no precision specifier is present. The “E” exponent character in the resulting string is always followed by a plus or minus sign and at least three digits. A width specifier sets the minimum field width for a conversion. If the resulting string is shorter than the minimum field width, it is padded with blanks to increase the field width. The default is to right-justify the result by adding blanks in front of the value, but if the format specifier contains a left-justification indicator (an ”-” en dash character preceding the width specifier), the result is left-justified by adding blanks after the value. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Fixed | The argument must be a floating-point value. The value is converted to a string of the form ”-ddd.ddd…”. The resulting string starts with a minus sign if the number is negative. The number of digits after the decimal point is given by the precision specifier in the format string—a default of 2 decimal digits is assumed if no precision specifier is present. A width specifier sets the minimum field width for a conversion. If the resulting string is shorter than the minimum field width, it is padded with blanks to increase the field width. The default is to right-justify the result by adding blanks in front of the value, but if the format specifier contains a left-justification indicator (an ”-” en dash character preceding the width specifier), the result is left-justified by adding blanks after the value. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| General | The argument must be a floating-point value. The value is converted to the shortest possible decimal string using fixed or scientific format. The number of significant digits in the resulting string is given by the precision specifier in the format string; a default precision of 15 is assumed if no precision specifier is present. Trailing zeros are removed from the resulting string, and a decimal point appears only if necessary. The resulting string uses the fixed-point format if the number of digits to the left of the decimal point in the value is less than or equal to the specified precision, and if the value is greater than or equal to 0.00001. Otherwise the resulting string uses scientific format. A width specifier sets the minimum field width for a conversion. If the resulting string is shorter than the minimum field width, it is padded with blanks to increase the field width. The default is to right-justify the result by adding blanks in front of the value, but if the format specifier contains a left-justification indicator (an ”-” en dash character preceding the width specifier), the result is left-justified by adding blanks after the value. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Number | The argument must be a floating-point value. The value is converted to a string of the form ”-d,ddd,ddd.ddd…”. The n format corresponds to the f format, except that the resulting string contains thousand separators. A width specifier sets the minimum field width for a conversion. If the resulting string is shorter than the minimum field width, it is padded with blanks to increase the field width. The default is to right-justify the result by adding blanks in front of the value, but if the format specifier contains a left-justification indicator (an ”-” en dash character preceding the width specifier), the result is left-justified by adding blanks after the value. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Money | The argument must be a floating-point value. The value is converted to a string that represents a currency amount. The conversion is controlled by the CurrencyString, CurrencyFormat, NegCurrFormat, ThousandSeparator, DecimalSeparator, and CurrencyDecimals parameters. If the format string contains a precision specifier, it overrides the value given by the CurrencyDecimals parameters. A width specifier sets the minimum field width for a conversion. If the resulting string is shorter than the minimum field width, it is padded with blanks to increase the field width. The default is to right-justify the result by adding blanks in front of the value, but if the format specifier contains a left-justification indicator (an ”-” en dash character preceding the width specifier), the result is left-justified by adding blanks after the value. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String | The argument must be a string. The string or character is inserted in place of the format specifier. The precision specifier, if present in the format string, specifies the maximum length of the resulting string. If the argument is a string that is longer than this maximum, the string is truncated. A width specifier sets the minimum field width for a conversion. If the resulting string is shorter than the minimum field width, it is padded with blanks to increase the field width. The default is to right-justify the result by adding blanks in front of the value, but if the format specifier contains a left-justification indicator (an ”-” en dash character preceding the width specifier), the result is left-justified by adding blanks after the value. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Hexadecimal | The argument must be an integer value. The value is converted to a string of hexadecimal digits. If the format string contains a precision specifier, it indicates that the resulting string must contain at least the specified number of digits; if the value has fewer digits, the resulting string is left-padded with zeros. A width specifier sets the minimum field width for a conversion. If the resulting string is shorter than the minimum field width, it is padded with blanks to increase the field width. The default is to right-justify the result by adding blanks in front of the value, but if the format specifier contains a left-justification indicator (an ”-” en dash character preceding the width specifier), the result is left-justified by adding blanks after the value. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Float | The argument must be an floating-point value.
The number being formatted is always rounded to as many decimal places as there are digit placeholders ('0' or '#') to the right of the decimal point. If the format string contains no decimal point, the value being formatted is rounded to the nearest whole number. If the number being formatted has more digits to the left of the decimal separator than there are digit placeholders to the left of the '.' character in the format string, the extra digits are output before the first digit placeholder. To allow different formats for positive, negative, and zero values, the format string can contain between one and three sections separated by semicolons, as follows: One section: The format string applies to all values. Two sections: The first section applies to positive values and zeros, and the second section applies to negative values. Three sections: The first section applies to positive values, the second applies to negative values, and the third applies to zeros. If the section for negative values or the section for zero values is empty, that is if there is nothing between the semicolons that delimit the section, the section for positive values is used instead. If the section for positive values is empty or if the entire format string is empty, the value is formatted using general floating-point formatting with 15 significant digits, corresponding to a call to FloatToStrF with the ffGeneral format. General floating-point formatting is also used if the value has more than 18 digits to the left of the decimal point and the format string does not specify scientific notation. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Date Time | Date Time Format strings are composed of specifiers that represent values to be inserted into the formatted string. Some specifiers (such as “d”) simply format numbers or strings. Other specifiers (such as ”/”) refer to locale-specific strings. In the following table, specifiers are given in lowercase. Case is ignored in formats, except for the “am/pm” and “a/p” specifiers.
|
NOTE: Various local options or parameters, such as DecimalSeparator or ThousandSeparator are used for some of these formatting options.
<#MyVar setValue="-123"> <#MyVar Format="'Decimal = '%.5d"> <#MyVar setValue="123"> <#MyVar Format="'Unsigned decimal = '%u"> <#MyVar setValue="12345.678"> <#MyVar Format="'Exponent = '%e"> <#MyVar setValue="12345.678"> <#MyVar Format="'Fixed = '%.2f"> <#MyVar setValue="12345.0001"> <#MyVar Format="'General = '%g"> <#MyVar setValue="12345.678872"> <#MyVar Format="'Number = '%.3n"> <#MyVar setValue="12345.678"> <#MyVar Format="'Money = '%.2m"> <#MyVar setValue="Hello"> <#MyVar Format="'String = '%s"> <#MyVar setValue="140"> <#MyVar Format="'Hexadecimal = '%x"> <#MyVar setValue="12345.678"> <#MyVar Format="'Float = '%0.##"> <#MyVar setValue="NOW"> <#MyVar Format="'Date = 'mm/dd/yyyy">
The above example will output:
Decimal = -00123 Unsigned decimal = 123 Exponent = 1.23456780000000E+004 Fixed = 12345.68 General = 12345.0001 Number = 12,345.679 Money = $12,345.68 String = Hello Hexadecimal = 8C Float = 12345.68 Date = 11/25/2012