AdaPower Logged in as Guest
Ada Tools and Resources

Ada 95 Reference Manual
Ada Source Code Treasury
Bindings and Packages
Ada FAQ


Join >
Articles >
Ada FAQ >
Getting Started >
Home >
Books & Tutorials >
Source Treasury >
Packages for Reuse >
Latest Additions >
Ada Projects >
Press Releases >
Ada Audio / Video >
Home Pages >
Links >
Contact >
About >
Login >
Back
Declaring Decimal Fixed Point Types (Matthew Heaney)

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.


(c) 1998-2004 All Rights Reserved David Botton