'How to Implement an Money Type in Ada?

I Try to convert Following Ada Code Package with ada2wsdl

package Bank is
   
   type Money is new Float; -- works
   type Money is delta 0.01 digits 15; -- dont work
  
end Bank;

The Command Line Tool gives following output

ada2wsdl: unsupported element kind Money

How i should implement the Money Type in Ada ?
Is That correkt ?



Solution 1:[1]

Because XML Schema has no fixed-point or binary-coded decimal (BCD) type, in the xsd: namespace, ada2wsdl was designed with the destination xsd type as the 1st-class citizen and the corresponding Ada type derived from that. Floating point should never be utilized for money because floating point can be imprecise in the least-significant digits for large amounts of money that are expected to be accurate right down to the last 0.01 monetary unit. The closest emulation in XML Schema for Ada's fixed-point type would be a string in the WWW UI delivered to Ada via the ada2wsdl as a string then converted in Ada code to Ada's fixed-point type.

Also (especially for a bank), the Money type should always contain an accompanying monetary unit along with the fixed-point number as an Ada record.

package Bank is
   type IdMonetaryUnit is (EUR, GBP, RUB, USD);
   type StrMoney is String(1..15); -- Use this in wsdl with radix-point implicitly implied at 0000000000000.00 for "000000000000000".
   type Money is
       record
           Value  : delta 0.01 digits 15;
           IdUnit : IdMonetaryUnit;
       end record;
end Bank;

For a bank, I would recommend more than 15 digits. I think that 18 is the bare minimum in the real world when considering all monetary units used in banking; certainly some ISO or banking-industry standard would specify that minimum field size for use in practice.

Solution 2:[2]

type Money is delta 0.01 digits 18;

Result: 36553462709287.80 EUR -> ok
Result: 18287169236628.28 EUR -> ok
Result: 12193767453669.50 EUR -> ok
Result:  9146196324860.35 EUR -> ok
Result:  7317375076173.70 EUR -> ok
Result:  6098044816860.81 EUR -> ok
Result:  5227037762542.62 EUR -> ok
Result:  4573751368852.46 EUR -> ok
Result:  4065621296766.90 EUR -> ok
Result:  3659105626024.01 EUR -> ok
php7 float

Result: 36553462709288.00 EUR -> false
Result: 18287169236628.00 EUR -> false
Result: 12193767453670.00 EUR -> false
Result:  9146196324860.40 EUR -> false
Result:  7317375076173.70 EUR -> ok
Result:  6098044816860.80 EUR -> false
Result:  5227037762542.60 EUR -> false
Result:  4573751368852.50 EUR -> false
Result:  4065621296766.90 EUR -> ok
Result:  3659105626024.00 EUR -> false

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Andreas ZUERCHER
Solution 2