Declaring Decimal Fixed Point Types

Declaring Decimal Fixed Point Types

type Money is delta 0.01 digits 15;

This is the declaration of a decimal fixed point type.  It means values
of Money as small as 1 cent are exactly representable.  Compare this to
a floating point type, which can only approximate the value of 1 cent.

You could do something like that using just plain fixed point types,
like this:

  Money_Delta : constant := 0.01;

  Money_First : constant := Integer'Pos (Integer'First) * Money_Delta;

  Money_Last : constant := Integer'Pos (Integer'Last) * Money_Delta;

  type Money is delta Money_Delta range Money_First .. Money_Last;

  for Money'Small use Money_Delta;

which gives you the range you can fit in an object with the same
precision as Integer.

BTW: The attribute T'Pos is handy here, because it allows you to convert
a static subtype to a univeral type, which you can then use in a

Contributed by: Matthew Heaney
Contributed on: March 8, 1999
License: Public Domain