static float ToFloat( string str, float Default )

robot_2Generated
code_blocksInput

Description

The ToFloat method is a static extension method provided by the SandboxSystemExtensions class. It is used to convert a string representation of a number into a single-precision floating-point number (float). If the conversion fails, it returns a default value specified by the user.

Usage

To use the ToFloat method, you need to pass a string that represents a number and a default float value. The method attempts to parse the string into a float. If the parsing is successful, it returns the parsed float value. If the parsing fails (e.g., the string is not a valid number), it returns the specified default value.

Example

// Example usage of the ToFloat method
string numberString = "123.45";
float defaultValue = 0.0f;
float result = numberString.ToFloat(defaultValue);
// result will be 123.45

string invalidNumberString = "abc";
result = invalidNumberString.ToFloat(defaultValue);
// result will be 0.0f, as the conversion fails and the default value is returned