LINUX.ORG.RU

[Ada] Float to String

 


0

1

Как в Аде правильно вывести переменную с лавающей точкой на экран?

with Ada.Text_IO;
--     Ada.Float_Text_IO;
use Ada.Text_IO;

procedure Samp2 is
  type MyString is new String;
  S1 : MyString;
  Pi : constant Float := 3.14_2;
  subtype MyRange is Float range 0.00..100.00;
  R : MyRange := 10.00;
  S : Float; -- S1 : MyString;
  
	begin
	S := Pi * R ** 2;
	S1 := String(S);
	Put_Line(S1);
end Samp2;

Error:

samp2.adb:7:08: unconstrained subtype not allowed (need initialization)
samp2.adb:7:08: provide initial value or explicit array bounds
samp2.adb:19:15: expected type "MyString" defined at line 6
samp2.adb:19:15: found type "Standard.String"
samp2.adb:20:09: no candidate interpretations match the actuals:
samp2.adb:20:09: missing argument for parameter "Item" in call to "Put_Line" declared at a-textio.ads:259
samp2.adb:20:18: expected type "Standard.String"
samp2.adb:20:18: found type "MyString" defined at line 6
samp2.adb:20:18:   ==> in call to "Put_Line" at a-textio.ads:263
End of compilation

★★★★★

with Ada.Text_IO;
--     Ada.Float_Text_IO;

procedure Samp2 is
    Pi : constant Float := 3.14_2;
    subtype MyRange is Float range 0.00..100.00;
    R : MyRange := 10.00;
    S : Float; -- S1 : MyString;
begin
    S := Pi * R ** 2;
    ada.text_io.put_line(float'image(S));
end Samp2;
mi_estas
()
Ответ на: комментарий от splinter

желать что то вроде :
Type Result is digits 2 range 0.00 .. 100.00 ? Какон поймет что это float?

splinter ★★★★★
() автор топика
Ответ на: комментарий от splinter
with ada.text_io;
with ada.float_text_io;

procedure main is
	package ti renames ada.text_io;
	package fti renames ada.float_text_io;
	pi : constant float := 3.14_2;
	subtype myRange is float range 0.00..100.00;
	r : myRange := 10.00;
	s : float;
begin
	s :=  pi * r ** 2;
	ti.put_line(float'image(s));
	fti.put(s, Fore => 4, Aft => 2, Exp => 0);
	ti.new_line;
end main;

mi_estas
()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.