Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Problema en Conversion de Fahrenheit a Celsius (https://www.clubdelphi.com/foros/showthread.php?t=87352)

FabianSiza 18-12-2014 23:53:29

Problema en Conversion de Fahrenheit a Celsius
 
Hola amigos estoy tratando de hacer un programa que convierta Farenheit a Celsius y todo estaba bien hasta que el numero a comvertir fue 1.85
al momento de calcular me aparece el siguiente dialogo "1.85" is not a valid integer value. que debo hacer!!

este es mi codigo

Código Delphi [-]
var
a,b,res:Real;
c:integer;
indice:integer;
begin
  c:=strtoint(Edit3.Text);

  a:=c-32;
  b:=a*5;
  res:=b/9;
 label4.Caption:=(floattostr(res)+' °C');

ecfisa 19-12-2014 00:30:47

Hola FabianSiza.

Usa alguna de las funciones StrToFloat, StrToFloatDef o TryStrToFloat, ya que 1.85 no es un valor entero.

Saludos :)

nlsgarcia 19-12-2014 05:33:25

FabianSiza,

Cita:

Empezado por FabianSiza
...estoy tratando de hacer un programa que convierta Fahrenheit a Celsius...

:rolleyes:

Revisa este código:
Código Delphi [-]
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    RadioGroup1: TRadioGroup;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
   RadioGroup1.ItemIndex := 0;
end;

function Fahrenheit2Celsius(F : Double) : Double;
begin
   Result := 5/9 * (F - 32);
end;

function Celsius2Fahrenheit(C : Double) : Double;
begin
   Result := C * 9/5 + 32;
end;

function Fahrenheit2Kelvin(F : Double) : Double;
begin
   Result := (F + 459.67) * 5/9;
end;

function Kelvin2Fahrenheit(K : Double) : Double;
begin
   Result := K * 9/5 - 459.67;
end;

function Kelvin2Celsius(K : Double) : Double;
begin
   Result := K - 273.15;
end;

function Celsius2Kelvin(C : Double) : Double;
begin
   Result := C + 273.15;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
   Temperature1, Temperature2 : Double;

begin

   Temperature1 := StrToFloatDef(Edit1.Text,0);

   case RadioGroup1.ItemIndex of
     0 : Temperature2 := Fahrenheit2Celsius(Temperature1);
     1 : Temperature2 := Celsius2Fahrenheit(Temperature1);
     2 : Temperature2 := Fahrenheit2Kelvin(Temperature1);
     3 : Temperature2 := Kelvin2Fahrenheit(Temperature1);
     4 : Temperature2 := Kelvin2Celsius(Temperature1);
     5 : Temperature2 := Celsius2Kelvin(Temperature1);
   end;

   Edit2.Text := FloatToStr(RoundTo(Temperature2,-3));

end;

end.
El código anterior en Delphi 7 sobre Windows 7 Professional x32, permite realizar conversiones de temperatura, como se muestra en la siguiente imagen:



Espero sea útil :)

Nelson.

FabianSiza 19-12-2014 21:03:34

Muchas gracias me a servido el codigo


La franja horaria es GMT +2. Ahora son las 04:36:14.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi