🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
Creating numeric types
This page was created by Lars.olofsson on 2020-06-24. Last edited by Wikiadmin on 2026-07-29.

You can create a Decimal value in an EAL expression when you need a numeric value with the Decimal type, for example when assigning a money-related value or calling a Decimal conversion method.

Create a Decimal value

Use Decimal.create(<number>) to create a Decimal from a numeric value.

Decimal.create(100)

This expression creates a Decimal with the value 100.

You can use the created value as part of a larger expression. For example, create a Decimal value and convert it to a 32-bit integer:

Decimal.create(5.4).ToInt32

The result is 5. The conversion to an integer removes the fractional part (.4).

Use Decimal values in assignments

Numeric types must conform when you assign one value to another. If an attribute expects a Decimal, create or convert the value to Decimal before assigning it.

For example, this creates a Decimal value that can be used where a Decimal is expected:

self.SomeDecimal:=Decimal.create(100)

When the source is already another numeric type, use the appropriate numeric conversion operator instead. For example:

self.SomeDecimal:=self.SomeDouble.todecimal

Review Documentation:Number conversions for the available conversions between int, float, double, and decimal, and for the precision implications of each conversion.

Create a value or parse text

Decimal.create creates a Decimal from a numeric value. If the input is text, use Decimal.parse instead.

Decimal.parse('10')

This returns a Decimal with the value 10. If the text cannot be converted, parsing returns NULL; for example, Decimal.parse('x').isNull returns true. See Documentation:Parse for parsing behavior and error handling.

Choose the numeric type deliberately

A data type defines the values an attribute can hold and the operations available for it. Use Decimal where your model requires Decimal values; use Integer for whole-number values. Numeric addition and the resulting numeric type are described in Documentation:OCLOperators addition.

Changing an existing modeled attribute from one type to another is a separate task. For approaches that preserve existing data while you test a conversion, see Documentation:Attribute or Data Type Conversion.

See also

[[Category:Attributes and data types [Beginner]]]