swirl Guide to OmniMark 5   OmniMark home
docs home 
IndexConceptsTasksSyntaxLibrariesOMX VariablesErrors
 
     
Financial calculation

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 literal BCD values must be preceded by the keyword bcd.

  include "ombcd.xin"

  process
      local bcd price
      local bcd tax-rate
      local integer quantity
      local bcd total

      set price to bcd 19.95
      set tax-rate to bcd 0.07
      set quantity to 28
      set total to price * quantity * (1 + tax-rate)
      output "<$,NNZ.ZZ>" % 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 code shows how to read a decimal number from an HTML form and assign 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 stream cgi-data variable
      local bcd price
      local bcd tax-rate
      local integer quantity
      local bcd total

      CGIGetEnv into cgi-data
      CGIGetQuery into form-data

      set price to bcd form-data{"price"}
      set tax-rate to bcd 0.07
      set quantity to 28
      set total to price * quantity * (1 + tax-rate)
      output "Content-type: text/html"
          || crlf
          || crlf
          || "<html><body>"
          || "<H1>Order confirmation</H1>"
          || "Your total comes to: "
          || "<$,NNZ.ZZ>" % total

       
----

Top [ INDEX ] [ CONCEPTS ] [ TASKS ] [ SYNTAX ] [ LIBRARIES ] [ OMX ] [ OMX ] [ ERRORS ]

Generated: August 11, 2000 at 3:06:20 pm
If you have any comments about this section of the documentation, send email to docerrors@omnimark.com

Copyright © OmniMark Technologies Corporation, 1988-2000.