--  Fixed point read and written (D197): 'Value and 'Valid_Value count the literal's exact
--  value in smalls, truncated toward zero; Fixed_IO and Decimal_IO write the value's exact
--  digits, rounded to the nearest (halves away from zero), as 'Image does.
with Ada.Text_IO; use Ada.Text_IO;
procedure Main is
   type Volts is delta 0.125 range -10.0 .. 10.0;
   type Money is delta 0.01 digits 10;
   package Volts_IO is new Fixed_IO (Volts);
   package Money_IO is new Decimal_IO (Money);
   V : Volts;
   M : Money;
   Last : Positive;
   Buffer : String (1 .. 12);
begin
   --  'Value: -3.3 is -26.4 smalls, so -26 of them, -3.25
   if Volts'Valid_Value (" -3.3 ") then
      Put_Line (Volts'Image (Volts'Value (" -3.3 ")));
   end if;
   Put_Line (Boolean'Image (Volts'Valid_Value ("11.0")) & " " & Boolean'Image (Volts'Valid_Value ("1.")));
   if Money'Valid_Value ("16#FF.8#") then
      Put_Line (Money'Image (Money'Value ("16#FF.8#")));
   end if;
   --  Put: Fore, Aft and Exp
   Volts_IO.Put (2.375); New_Line;
   Volts_IO.Put (-3.25, Fore => 5, Aft => 4); New_Line;
   Volts_IO.Put (0.125, Aft => 2, Exp => 3); New_Line;
   Money_IO.Put (1234.56); New_Line;
   Money_IO.Put (-0.07, Exp => 2); New_Line;
   --  Get from a string reads the longest literal, here up to Last
   Volts_IO.Get (" 7.6xyz", V, Last);
   Volts_IO.Put (V); Put_Line (Positive'Image (Last));
   Money_IO.Get ("12_345.678", M, Last);
   Money_IO.Put (M); Put_Line (Positive'Image (Last));
   Money_IO.Put (Buffer, M, Aft => 3);
   Put_Line ("[" & Buffer & "]");
   Money_IO.Put (Buffer (1 .. 4), M);
exception
   when Data_Error | End_Error =>
      Put_Line ("not read");
   when Layout_Error =>
      Put_Line ("does not fit");
end Main;
