422 users using DBSP now!
home -> documentation -> language reference -> FORMAT property


Description

Optional property for the EXPVAL and field tags, the FORMAT property allows to convert a floating point value into different kinds of representation according to the format, precision and digit arguments.


Syntax

<#EXPVAL EXPRESSION="anExpression" [FORMAT="Format:Precision:Digits"] />

OR

<#FIELD1 EXPRESSION="anExpression" [FORMAT="Format:Precision:Digits"] />

FORMAT The available formats are:

General. General number format. The value is converted to the shortest possible decimal string using fixed or scientific format. Trailing zeros are removed from the resulting string, and a decimal point appears only if necessary. The resulting string uses 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, and the Digits parameter specifies the minimum number of digits in the exponent (between 0 and 4).
Exponent. Scientific format. The value is converted to a string of the form "-d.ddd...E+dddd". The resulting string starts with a minus sign if the number is negative, and one digit always precedes the decimal point. The total number of digits before the exponent in the resulting string (including the one before the decimal point) is given by the Precision parameter. The "E" exponent character in the resulting string is always followed by a plus or minus sign and up to four digits. The Digits parameter specifies the minimum number of digits in the exponent (between 0 and 4).
Fixed. Fixed point format. 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, and at least one digit always precedes the decimal point. The number of digits after the decimal point is given by the Digits parameter--it must be between 0 and 18. If the number of digits to the left of the decimal point is greater than the specified precision, the resulting value will use scientific format.
Money. Currency format. The value is converted to a string that represents a currency amount. The conversion is controlled by the Currency Format in the International section of the Windows Control Panel. The number of digits after the decimal point is given by the Digits parameter--it must be between 0 and 18.
Number. Number format. The value is converted to a string of the form "-d,ddd,ddd.ddd...". The resulting string contains thousand separators.
Percent. Percent format. The value is converted to a string of the form "-d.dd %". The resulting string contains thousand separators.
PRECISION The Precision parameter specifies the precision of the given value. The maximum precision allowed for a floating point value is 18.
DIGITS The Digits and Format parameters together control how the value is formatted into a string.

Note: If the given value is a NAN (not-a-number), the resulting string is ignored and will not be inserted in the page.

References

Expression
EXPVAL


Applications

Use the FORMAT property to change a floating point value into different kind of representations. For example, use the MONEY format in order to present floating point values as amounts or the EXPONENT format for scientific numbers. See the examples below.


Operative examples

Example 1. DBSP formatting options.

This example shows the usage and variants for the FORMAT property..

Source code


File: examples/FormatEx.dbsp

   <!--FOR.dbsp-->
  
 
    

FORMAT example

 
    

This example shows the usage and variants for the FORMAT property.


    
    <#SETCOOKIE NAME="X" VALUE="32763.182732"/>
    
   

Suppose that you have the value X= <#X/>


    
   

Formatting the value with the GENERAL format, 12 digits of precision and a 4 digits mantissa: X = <#X FORMAT="GENERAL:12:4"/>


   

Formatting the value with the EXPONENT format, 12 digits of precision and a 4 digits mantissa: X = <#X FORMAT="EXPONENT:12:4"/>


   

Formatting the value with the FIXED format, 12 digits of precision and a 4 digits mantissa: X = <#X FORMAT="FIXED:12:4"/>


   

Formatting the value with the MONEY format, 12 digits of precision and a 2 digits mantissa: X = <#X FORMAT="MONEY:12:2"/>


   

Formatting the value with the NUMBER format, 12 digits of precision and a 4 digits mantissa: X = <#X FORMAT="NUMBER:12:4"/>


   

Formatting the value with the PERCENT format, 12 digits of precision and no mantissa: X = <#X FORMAT="PERCENT:12:0"/>


     
 
  



Test example