with Ada.Numerics.Generic_Elementary_Functions;
with Ada.Strings.Fixed;
+--with Ada.Strings.Unbounded;
--with Ada.Text_IO;
package body Formatting_Helpers is
--Integer_Part_F := FH_Float'Floor(PNum / Expanded);
--Ada.Text_IO.Put_Line("((PNum / Expanded) - Integer_Part_F) * Expanded = " & FH_Float'Image(((PNum / Expanded) - Integer_Part_F) * Expanded));
Decimal_Part := ((PNum / Expanded) - Integer_Part_F) * ExpDecimals;
- if Decimal_Part < 1.0 then
- Decimal_Part := 0.0;
- end if;
+ Decimal_Part := FH_Float'Rounding(Decimal_Part);
Exponent_Part := Integer(Log_Arg_Floored);
Integer_Part := Integer(Integer_Part_F);
package FHEF is new Ada.Numerics.Generic_Elementary_Functions(FH_Float);
use FHEF;
- EPSILON: constant FH_Float := 10.0 ** (-(Decimals + 1));
+ EPSILON: constant FH_Float := 10.0 ** (-Decimals);
VDIV: constant FH_Float := 10.0 ** Decimals;
Log_Num: FH_Float;
Diff: Integer;
Zero_String: UB_Text;
+ RNum: FH_Float := Num + EPSILON;
begin
if Num = 0.0 then
Log_Num := 1.0;
else
- Log_Num := FH_Float'Ceiling(Log(Base => 10.0, X => Num));
+ Log_Num := FH_Float'Ceiling(Log(Base => 10.0, X => RNum));
--Ada.Text_IO.Put_Line("Log_Num: " & FH_Float'Image(Log_Num));
- --Ada.Text_IO.Put_Line("Num: " & FH_Float'Image(Num));
- if Abs(FH_Float'Remainder(Num, VDIV / 10.0)) <= EPSILON then
+ --Ada.Text_IO.Put_Line("Num: " & FH_Float'Image(Num) & " Rem: " & FH_Float'Image(FH_Float'Remainder(RNum , VDIV / 10.0)));
+ if Abs(FH_Float'Remainder(RNum, VDIV / 10.0)) <= EPSILON then
--Ada.Text_IO.Put_Line("Fixing up zeros - divisible by 100");
Log_Num := Log_Num + 1.0;
end if;