AnsiStrings have a ToFloat() method that you can use. Something like this will do the trick:
//Save the string as a float
float SomeVariable = TheString.ToFloat();
//Test if the float is a decimal or an int
if((int)SomeVariable == SomeVariable)
{
//Do whatever you want to do
}
This code takes your AnsiString (TheString) can saves it in SomeVariable as a floating point decimal, then tests if that float equals itself once typecasted as an integer.
Some AnsiStrings can't be evaluated for a float, and the only way I know to tell if a string can be evaluated as a float is to iterate through each character and test it. If you need me to do so I could post a sample...
try
{
int x = MyString.ToInt();
float y = MyString.ToDouble();
// check valid range.
// set the database or whatever to new value.
}
catch (...)
{
// Code that says x wasn't an int or y wasn't a double.
}
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.