I am using CodeGear C++ Builder 2009. I am getting an error, and I don't understand why. Here's my code:
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?
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?