Home

String to Floating-Point Conversion

     

Introduction

 

To convert the value of a string to floating number, use the UnicodeString::ToDouble() method. Its syntax is:

double __fastcall ToDouble() const;
   

Here is an example:

//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
	double Value1 = Edit1->Text.ToDouble();
	double Value2 = Edit2->Text.ToDouble();
	
	double Value3 = Value1 + Value2;
	Edit3->Text = Value3;
}
//---------------------------------------------------------------------------

Another function used to convert a string to a floating-point value is the StrToFloat() function whose syntax is:

Extended __fastcall StrToFloat(const UnicodeString S);

This function takes one argument, which is the string to convert. The function returns a long double-precision value. Here is an example:

//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
	double Value1 = StrToFloat(Edit1->Text);
	double Value2 = StrToFloat(Edit2->Text);
	
	double Value3 = Value1 + Value2;
	Edit3->Text = Value3;
}
//---------------------------------------------------------------------------
 
 
     
 

Home Copyright © 2010-2016, FunctionX