swirl
Guide to OmniMark 7   OmniMark home
docs home 
IndexConceptsTasksSyntaxLibrariesLegacy LibrariesErrors
 
  Related Syntax    
operator  

truncate

 

 

Return type: BCD
Returns:       

A BCD or floating point number truncated to a whole number. If a precision is specified, the value is truncated to the multiple of that precision.



Syntax
  truncate bcd-expression (by precision)?

  truncate float-expression (by precision)?


Purpose

Use truncate to cut off trailing digits from:

If you do not specify the precision, you will truncate to the nearest integer.

Import either ombcd.xmd or omfloat.xmd 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:

  import "ombcd.xmd" unprefixed
  process
      local bcd pi initial {"3.14179"}
      local bcd radius  initial {"75"}
      local bcd area

      set area to truncate (pi * radius * radius)
      output "Area of a circle (truncated) with radius of "
          || "d" % radius
          || " = "
          || "d" % area
          || "%n"
  ; Output: "Area of a circle (truncated) with radius of 75 = 17672"

Floating Point Example:

Calculate the area of a circle:

  import "omfloat.xmd" unprefixed
  process
      local float radius  initial {"75"}
      local float area

      set area to truncate (pi * radius * radius)
      output "Area of a circle (truncated) with radius of "
          || "d" % radius
          || " = "
          || "d" % area
          || "%n"
  ; Output: "Area of a circle (truncated) with radius of 75 = 17672"

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

  import "ombcd.xmd" unprefixed
  process
      local bcd exchange-rate initial {1.4994}
      local bcd us-price initial {125.00}
      local bcd canadian-price

      set canadian-price to truncate (us-price*exchange-rate) by 0.01
      output "us "
          || "<$,NNZ.ZZ>" % us-price
          || " = "
          || "<$,NNZ.ZZ>" % canadian-price
          || " cdn %n"
  ; Output: "US $125.00 = $187.42 CDN"

The precision specifier must be a power of 10, or an error occurs.

    Related Syntax
   round
   ceiling
   floor
 
 
 

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

OmniMark 7.1.2 Documentation Generated: June 28, 2005 at 5:45:55 pm
If you have any comments about this section of the documentation, send email to [email protected]

Copyright © Stilo Corporation, 1988-2005.