|
Sometimes is necessary to make certain calculations and place the result at some point in the page. Even though you can use the SETCOOKIE element for this purpose, you don't have the necessity to store the value in memory; you just want to present the result. This exactly is the function of the EXPVAL Tag.
The EXPVAL tag
This tag evaluates the expression contained in the EXPRESSION property and inserts the resulting value instead.
Consider the next example:
|
<p>TAX: <#EXPVAL EXPRESSION="AMOUNT*0.10"/></p>
|
The code above will evaluate the expression contained in the EXPRESSION property and replace the tag with the obtained result. The final document will contain something like this:
Formatting the result
If the result is numeric, you could give some format in order to improve the presentation of the data. The syntax of the FORMAT property is listed below:
|
<#... FORMAT="format:precision:digits"/>
|
format is the format structure to use in order to present the value. It could have these values: GENERAL, EXPONENT, FIXED, MONEY, NUMBER or PERCENT. If you want a detailed explanation of each format, press here.
precision specifies the precision of the given value. It should be from 7 to 18.
digits specify the number of digits to present after the decimal point.
Examples
Example 1. Runtime calculations.
This example shows how to calculate values on the fly using the EXPVAL tag.
Source code
File: examples/Ex6_6_1.dbsp
<html> <head> <title>Calculating values on the fly</title> </head> <body> <h1>Calculating values on the fly</h1> <hr> <p>This example shows how to calculate values at run time. The PPP column and the totals are calculated on the fly.</p> <table cellpadding="2" border="1" cellspacing="1"> <tr> <th>Country</th> <th>Population</th> <th>GNI *</th> <th>PPP *</th> </tr> <#SETCOOKIE NAME="TOTALPOPULATION" VALUE="0"/> <#SETCOOKIE NAME="TOTALGNI" VALUE="0"/> <#SETCOOKIE NAME="TOTALPPP" VALUE="0"/> <#SETCOOKIE NAME="COUNTRYCOUNT" VALUE="0"/> <#DATASET ALIAS="OPEX" QUERYID=16> <tr> <td><#COUNTRY/></td> <td align="center"><#POPULATION FORMAT="NUMBER:10:0"/></td> <td align="center"><#GNI FORMAT="MONEY:10:2"/></td> <td align="center"><#EXPVAL EXPRESSION="(GNI/POPULATION)*1000" FORMAT="MONEY:12:2"/></td> </tr> <#SETCOOKIE NAME="TOTALPOPULATION" EXPRESSION="TOTALPOPULATION+POPULATION"/> <#SETCOOKIE NAME="TOTALGNI" EXPRESSION="TOTALGNI+GNI"/> <#SETCOOKIE NAME="TOTALPPP" EXPRESSION="TOTALPPP+(GNI/POPULATION)*1000"/> <#SETCOOKIE NAME="COUNTRYCOUNT" EXPRESSION="COUNTRYCOUNT+1"/> <#/DATASET> <tr> <th align="Center">Totals</th> <th><#TOTALPOPULATION FORMAT="NUMBER:10:0"/></th> <th><#TOTALGNI FORMAT="MONEY:10:2"/></th> <th><#TOTALPPP FORMAT="MONEY:10:2"/></th> </tr> <tr> <th align="Center">Average</th> <th><#EXPVAL EXPRESSION="TOTALPOPULATION/COUNTRYCOUNT" FORMAT="NUMBER:10:0"/></th> <th><#EXPVAL EXPRESSION="TOTALGNI/COUNTRYCOUNT" FORMAT="MONEY:10:2"/></th> <th><#EXPVAL EXPRESSION="TOTALPPP/COUNTRYCOUNT" FORMAT="MONEY:10:2"/></th> </tr> </table> <BR> <B>GNI</B> - Gross National Income (in thousands of dollars)<br> <B>PPP</B> - Purchase Power <br><br> </body> </html>
|
SQL Sentence: ID=16
|
SELECT COUNTRY, POPULATION, GNI
FROM COUNTRYSTATS
ORDER BY COUNTRY
|
Test example
Previous | Next
|