Number conversions
No edit summary
No edit summary
Line 1: Line 1:
The numeric types float, double, decimal and int are sort of apples of the same tree and MDriven expose ways to go from all numeric types to decimal. The operator is called toDecimal.
The numeric types float, double, decimal, and int are sort of apples of the same tree and MDriven exposes ways to go from all numeric types to decimal. The operator is called toDecimal.


Sometimes you may want to assign from one type to another like this:
Sometimes, you may want to assign from one type to another like this:
  self.PaymentMenuRequest.VatPercent:=vTypAvBiljett.BiljettPrisMoms
  self.PaymentMenuRequest.VatPercent:=vTypAvBiljett.BiljettPrisMoms
but you get an error like: 998: In ":=", one of the arguments must conform to the other (Nullable<System.Double> and Nullable<System.Decimal> does not)
but you get an error like 998: In ":=", one of the arguments must conform to the other (Nullable<System.Double> and Nullable<System.Decimal> do not).


Solve like this:  
Solve like this:  
  self.PaymentMenuRequest.VatPercent:=vTypAvBiljett.BiljettPrisMoms.todouble
  self.PaymentMenuRequest.VatPercent:=vTypAvBiljett.BiljettPrisMoms.todouble
These are valid assignments but you change precision and loose fractions when converting to simpler types
These are valid assignments but you change precision and lose fractions when converting to simpler types:
  self.SomeInt:=self.SomeDouble
  self.SomeInt:=self.SomeDouble


Line 19: Line 19:


  self.SomeDouble:=self.SomeDecimal.todouble
  self.SomeDouble:=self.SomeDecimal.todouble
[[Category:OCL]]
[[Category:OCL]]

Revision as of 08:15, 28 February 2023

The numeric types float, double, decimal, and int are sort of apples of the same tree and MDriven exposes ways to go from all numeric types to decimal. The operator is called toDecimal.

Sometimes, you may want to assign from one type to another like this:

self.PaymentMenuRequest.VatPercent:=vTypAvBiljett.BiljettPrisMoms

but you get an error like 998: In ":=", one of the arguments must conform to the other (Nullable<System.Double> and Nullable<System.Decimal> do not).

Solve like this:

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

These are valid assignments but you change precision and lose fractions when converting to simpler types:

self.SomeInt:=self.SomeDouble
self.SomeDouble:=self.SomeInt
self.SomeDecimal:=self.SomeInt
self.SomeDecimal:=self.SomeDouble.todecimal
self.SomeInt:=self.SomeDecimal
self.SomeDouble:=self.SomeDecimal.todouble
This page was edited 96 days ago on 02/10/2024. What links here