🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators toDecimal
This page was created by Charles on 2024-09-21. Last edited by Wikiadmin on 2026-07-29.

You use toDecimal in OCL expressions when you need an Integer or Float value to be treated as a Decimal, especially before using it with Decimal attributes.

Purpose

toDecimal converts a numeric value to a Decimal value.

Use it to align the numeric types on both sides of a calculation. For example, when Total is a Decimal attribute, convert the numeric constant before multiplying it:

self.Total * 0.10.ToDecimal

If self.Total is 50.00, this expression evaluates to 5.0.

Syntax

Call toDecimal on the numeric value that you want to convert:

number.toDecimal

The operator converts an Integer or Float to Decimal.

Input value type Expression Result type
Integer 45.toDecimal Decimal
Float 0.10.ToDecimal Decimal

Use Decimal values in calculations

Use toDecimal when a calculation combines a Decimal attribute with a numeric literal or another value that is not already Decimal.

For example, this mixed-type formula can produce a type error when Total is Decimal:

self.Total * 0.10

Convert the constant to Decimal to align the operands:

self.Total * 0.10.ToDecimal

This is particularly relevant when an expression is evaluated dynamically with ScriptEval. The ScriptEval example uses this conversion to correct an error stating that no multiplication operator accepts the mixed parameter types.

Conversion behavior

  • Use toDecimal with numbers, not with text.
  • The conversion can round very long decimal values to fit Decimal limits.
  • Convert values at the point where their type must match the rest of the expression. In the example above, converting 0.10 makes it compatible with a Decimal Total.

For conversion of text values, see Parse. Date and DateTime text conversions are documented separately in strToDate and strToDateTime.

See also