swirl
Guide to OmniMark 9   OmniMark home
docs home 
IndexConceptsTasksSyntaxLibrariesLegacy LibrariesErrors
 
     

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.

  import "ombcd.xmd" unprefixed
  
  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>" % 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:

  import "ombcd.xmd" unprefixed
  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 form-data{"price"}
      set tax-rate to 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 ] [ LEGACY LIBRARIES ] [ ERRORS ]

OmniMark 9.1.0 Documentation Generated: September 2, 2010 at 1:35:14 pm
If you have any comments about this section of the documentation, please use this form.

Copyright © Stilo International plc, 1988-2010.