Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Delphi: Для новичков > Real <-> Str


Автор: XoopeR 23.11.2007, 09:15
Подстажите, уже замаялся =)

Как реализовать???
Кусок кода
Код

var
a, b, c, e, f: real;

begin
a:=1;
b:=2.5;
c:=3.5;

e:=StrToInt(Edit1.Text); // Вот здесь сомнения =) Но другого кода не знаю
f:=StrToInt(Edit2.Text);  // ??

q:=a+b+c/(e+f);

Memo1.lines:=IntToStr(q); //??

end;



Как реализовать переход строки(Str)  в Real?

Автор: Alexeis 23.11.2007, 09:53
Цитата(XoopeR @  23.11.2007,  09:15 Найти цитируемый пост)
строки(Str)  в Real?

  StrToFloat

Автор: EvilsInterrupt 23.11.2007, 12:59
Alexeis, 
Может это лучше будет? :

Цитата

SysUtils.TryStrToFloat Function

Description
Use TryStrToFloat to convert a astring, S, to a floating-point value. S must consist of an optional sign (+ or -), a string of digits with an optional decimal point, and an optional mantissa. The mantissa consists of 'E' or 'e' followed by an optional sign (+ or -) and a whole number. Leading and trailing blanks are ignored. 


Автор: Alexeis 23.11.2007, 13:11
Цитата(EvilsInterrupt @  23.11.2007,  12:59 Найти цитируемый пост)
Может это лучше будет? :

  Если бы это лучше, то никто бы не делал 2е функции. Все зависит от ситуации. 

Автор: XoopeR 23.11.2007, 13:16
Ругается ((

На эту строчку

 Memo1.Lines:=FloatToStr(g);

[Error] Unit1.pas(43): Incompatible types: 'TStrings' and 'String'
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'

Что ему надо ещё?  smile 

Код

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Memo1: TMemo;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var a, b, c, d, e, f, g:Real;


begin
 a:=1;
 b:=1.5;
 c:=2.5;

 e:=StrToFloat(Edit1.Text);
 f:=StrToFloat(Edit2.Text);

 g:=a+b+c+e+f;

 Memo1.Lines:=FloatToStr(g);

end;

end.



Автор: THandle 23.11.2007, 13:23
Цитата(XoopeR @  23.11.2007,  13:16 Найти цитируемый пост)
Memo1.Lines:=FloatToStr(g);

Номер то строки укажи. 
Или в Memo1.Text засунь.

Автор: XoopeR 23.11.2007, 13:42
Урааа!!! Спасибо  smile  Я программист  smile 

Автор: ivan219 23.11.2007, 20:21
Код

Memo1.Lines.Add(FloatToStr(g));

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)