Numeric conversions

Web Site  Methods

 
Str::ToInt
Str::ToFloat
Str::ToDouble
 

int ToInt (BOOL* error = NULL) const
float ToFloat (BOOL* error = NULL) const
double ToDouble (BOOL* error = NULL) const

These three methods are used when the string must be converted to a number.

The result of the conversion is returned as a result from the method.  If an error occurs, the behavior is as follows:

The rules for the actual number conversion are the same as those of the strtol and strtod C RTL functions.

Example:

   Str s ("42.80");
   BOOL error;
   double v = s.ToDouble(&error);
   ASSERT(v == 42.80);
   ASSERT(error == FALSE);

 

STR_NO_RTLIBRARY compatibility note

If STR_NO_RTLIBRARY is defined, your program cannot use floating point numbers. ToFloat and ToDouble will not be available at all.

 

See also: Basic operations