🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
Double
This page was created by Stephanie on 2023-05-19. Last edited by Wikiadmin on 2026-07-29.

You use Double attributes in MDriven Designer when a model value needs a floating-point number, such as a measurement or calculated numeric value, and use .todouble when an OCL expression must produce a Double.

What Double represents

Double is a numeric attribute type for floating-point values. It represents numbers with a fractional part, for example 2.5, 0.2222, or -17.8. Floating-point values use binary representation and can therefore contain small rounding differences.

Use Double for values where floating-point precision is appropriate, such as a measurement or a calculated technical value. Do not use Double when the value must retain exact decimal places, such as an amount of money, tax, or a price. Use Decimal for those values.

Requirement Use Example
A measured or calculated floating-point value Double A length, temperature, or technical ratio
An amount that must retain exact decimal places Decimal Price 49.95, tax, or invoice total
A whole-number count Integer Number of items: 12

Create a Double attribute

In MDriven Designer, set the attribute's type to Double in the class diagram.

For example, a class can have these attributes:

Class Attribute Type Example value
Product Weight Double 2.5
Product UnitPrice Decimal 49.95
OrderLine Quantity Integer 3

The model type matters when you assign a value in OCL or EAL. An expression assigned to a Double attribute must conform to Double, or you must convert it.

Use Double in OCL and EAL

You can calculate with Double values in OCL expressions. For example, if both attributes are Double, multiply them directly:

self.TotalWeight := self.Weight * self.QuantityAsDouble

The multiplication result is a numeric value determined by the operand types. See the multiplication operator for multiplication examples and behavior.

Convert another numeric value to Double

Use .todouble when the receiving attribute is Double and the expression has another numeric type. This resolves type-conformance errors such as an assignment between nullable Decimal and nullable Double.

self.PaymentMenuRequest.VatPercent := vTypAvBiljett.BiljettPrisMoms.todouble

This conversion is especially important when the source value is Decimal:

self.SomeDouble := self.SomeDecimal.todouble

Conversions can change precision. Converting to an Integer also discards the fractional part:

self.SomeInt := self.SomeDouble

For the available numeric conversions and more assignment examples, see Documentation:Number conversions.

Keep numeric types aligned

Use the same numeric type throughout a calculation when the result is assigned to a typed attribute. Mixing Decimal and Double can cause an operator or assignment error.

For example, if self.Total is Decimal, make the numeric constant Decimal before multiplying it:

self.Total * 0.10.ToDecimal

Do not mix a Decimal amount with a Double constant unless you explicitly convert one side to the required type. This is particularly important in expressions evaluated through ScriptEval, where you must state the expected return type and the expression must type-check in its object context.

Precision and comparison

A Double is a floating-point value. Some decimal-looking values cannot be represented exactly in binary, so calculations can produce a value that is very close to, but not exactly, the expected decimal result.

For example, do not base a business rule requiring an exact monetary amount on a Double equality comparison. Store and calculate that amount as Decimal instead.

The same floating-point consideration applies to Float. Read Documentation:Float for a related overview of floating-point values.

Remainders

For an IEEE remainder calculation, use the number operation documented in Number::ieeereminder(r:Number). Its result is not the same as the ordinary remainder operator because it uses a different quotient rule.

See also

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