Is there some kind of implemented function that would allow to transform an integer to float and vice versa?
I managed to write a short function that transforms an integer to float:
function Transform(First: Integer) return Float is
A: Integer := First;
B: Float := 0.0;
begin
For_Loop:
for I in Integer range 1 .. A loop
B := B + 1.0;
end loop For_Loop;
return B;
end Transform;
But I don't know how to go from Float to Integer.
Ada can do explicit type conversions
with Ada.Text_IO; use Ada.Text_IO;
procedure Convert is
A: Integer:= 4;
B: Float;
C: Float := 6.8;
D: Integer;
begin
B := Float(A);
Put_Line(Float'Image(B));
D:= Integer(C);
Put_Line(Integer'Image(D));
end Convert;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With