swirl Guide to OmniMark 5   OmniMark home
docs home 
IndexConceptsTasksSyntaxLibrariesOMX VariablesErrors
 
  Related Syntax   Related Concepts  
operator   floor    

Return type: BCD
Returns:       

If the value is greater than zero, it is truncated to the specified precision. If the value is less than zero, it is rounded down to the nearest multiple of the specified precision.



Syntax
  floor bcd-expression  (by precision)?

  floor float-expression (by precision)?


Purpose

Use floor to round down:

If you include the keyword "by" and specify the precision, floor will round down to the multiple of the precision you have specified.

If you do not include the keyword "by" and do not specify the precision, floor will round down to the next integer whose value is less than the expression.

For values greater than zero, floor works like truncate. For values less than zero, floor rounds down to the next whole number less than or equal to the original value.

Include either ombcd.xin or omfloat.xin in your program after deciding whether you want BCD mathematics (excellent for financial calculations) or floating point mathematics (excellent for extremely large numbers).

BCD Example:

Calculate the area of a circle:

  include "ombcd.xin"
  process
      local bcd pi  initial {"3.14179"}
      local bcd radius  initial {"74"}
      local bcd area

      set area to floor (pi * radius * radius)
      output "area of circle with radius " || "d" % radius || " is at least " || "d" % area || "%n" 

You can specify the precision of the truncation/rounding. The following program uses a precision of 0.01 to truncate/round the value at the whole cents position:

  include "ombcd.xin"
  process
      local bcd exchange-rate initial {1.4356}
      local bcd us-price  initial {129.95}
      local bcd canadian-price

      set canadian-price to floor (us-price*exchange-rate) by bcd 0.01
      output "us " || "<$,NNZ.ZZ>" % us-price || " is at least " || "<$,NNZ.ZZ>" % canadian-price || " cdn %n"

The precision specifier must be a power of 10.

Floating Point Example:

Calculate the area of a circle:

  include "omfloat.xin"
  process
      local float pi initial {"3.14179"}
      local float radius initial {"74"}
      local float area

      set area to floor (pi * radius * radius)
      output "Area of circle with radius " || "d" % radius || " = " || "d" % area || "%n" 

    Related Syntax
   round
   ceiling
   floor
   truncate
 
Related Concepts
   BCD data type
 
----  

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

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

Copyright © OmniMark Technologies Corporation, 1988-2000.