Financial Calculations

[Previous] [Next]

You can perform financial calculations in OmniMark using the BCD data type to represent monetary values and fractional numbers such as tax rates. Unlike floating-point numbers, BCD numbers provide accurate fractions for financial calculations.

The following code sample shows basic financial calculations using BCD numbers. Note that the keyword bcd must precede literal BCD values.

 include "ombcd.xin" process local bcd price local bcd tax-rate local integer quantity local bcd total set price to 19.95 set tax-rate to 0.07 set quantity to 28 set total to price * quantity * (1 + tax-rate) output "<$,NNZ.ZZ>" format total 

The format string "<$,NNZ.ZZ>" uses the BCD template language to create an output string with a leading $, commas separating digits into groups of three, and two digits after the decimal point.

The following CGI program reads a decimal number from an HTML form and assigns the value to a BCD number:

 include "ombcd.xin" include "omcgi.xin" declare #process-input has unbuffered declare #process-output has binary-mode process local stream form-data variable local bcd price local bcd tax-rate local integer quantity local bcd total CGIGetQuery into form-data set price to form-data{"price"} set quantity to form-data{"qty"} set tax-rate to 0.07 set total to price * quantity * (1 + tax-rate) output "Content-type: text/html" || crlf || crlf || "<html><body>" || "<H1>Order confirmation</H1>" || "<p>Your total comes to: " || "<$,NNZ.ZZ>" format total 

The following HTML document can be used to test the preceding CGI program:

 <HTML> <HEAD> <TITLE>Place an order</TITLE> </HEAD> <BODY> <H1>Place an order</H1> <FORM METHOD="POST" ACTION="bcd.xom"> Price: <INPUT TYPE="TEXT" NAME="price"></INPUT><BR> Quantity: <INPUT TYPE="TEXT" NAME="qty"></INPUT><BR> <INPUT TYPE="SUBMIT" VALUE="Calculate total with tax"> </FORM> </BODY> </HTML> 



XML and SOAP Programming for BizTalk Servers
XML and SOAP Programming for BizTalk(TM) Servers (DV-MPS Programming)
ISBN: 0735611262
EAN: 2147483647
Year: 2000
Pages: 150

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net