Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AnsiString conversion to double giving error

Status
Not open for further replies.

Shawnasie

Programmer
Aug 19, 2008
23
US
I am using CodeGear C++ Builder 2009. I am getting an error, and I don't understand why. Here's my code:

Code:
	if (angle < 0) {
	   angle = 360 - angle;
   }
   AnsiString zero;
   AnsiString str = AnsiString(angle);
   int dot = AnsiPos(".",str);
   AnsiString rounder = str.SubString(dot + 2, 1);
   AnsiString str2 = str.SubString(0,dot+1);
   angle = str2.ToDouble();
   if (rounder.ToInt() < 4) {
   	   angle += 0.01;
   }
   if (angle < 10) {  //Using zeros as placeholders
		zero = "00";
   } else if (angle < 100) {
		zero = "0";
   } else zero = "";

   [COLOR=red] AnsiString a = zero + AnsiString(angle); [/color]

I ran the code with angle = -90.432. With this code, I expect a = "450.4". As I run through each line, I get that str = "450.432", rounder = "3", str2 = "450.4", angle becomes 450.4. But at the last line I get the error: "Project raised exception class EConvertError with message "." is not a valid integer value."

At first I thought perhaps AnsiString() doesn't convert double. But I successfully converted from double the same way above that with AnsiString(angle). Does anyone know why this isn't working?

 
Okay, I found there was another problem, not with the AnsiString() conversion function. Sorry, everyone. I think I need to wait a little longer before I post.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top