Added TextToFloat()
I recently created a pull request for the raygui library (#309), which adds GuiFloatBox() that requires TextToFloat() to function properly
This commit is contained in:
parent
090b857912
commit
95e99b84a3
|
|
@ -1416,7 +1416,8 @@ RLAPI int TextFindIndex(const char *text, const char *find);
|
|||
RLAPI const char *TextToUpper(const char *text); // Get upper case version of provided string
|
||||
RLAPI const char *TextToLower(const char *text); // Get lower case version of provided string
|
||||
RLAPI const char *TextToPascal(const char *text); // Get Pascal case notation version of provided string
|
||||
RLAPI int TextToInteger(const char *text); // Get integer value from text (negative values not supported)
|
||||
RLAPI int TextToInteger(const char *text); // Get integer value from text
|
||||
RLAPI float TextToFloat(const char* text); // Get float value from text
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Basic 3d Shapes Drawing Functions (Module: models)
|
||||
|
|
|
|||
34
src/rtext.c
34
src/rtext.c
|
|
@ -1389,6 +1389,40 @@ int TextToInteger(const char *text)
|
|||
return value*sign;
|
||||
}
|
||||
|
||||
// Get float value from text
|
||||
float TextToFloat(const char* text)
|
||||
{
|
||||
float value = 0.0f;
|
||||
float floatingPoint = 0.0f;
|
||||
int sign = 1;
|
||||
|
||||
if ((text[0] == '+') || (text[0] == '-'))
|
||||
{
|
||||
if (text[0] == '-') sign = -1;
|
||||
text++;
|
||||
}
|
||||
|
||||
for (int i = 0; (((text[i] >= '0') && (text[i] <= '9')) || text[i] == '.'); i++)
|
||||
{
|
||||
if (text[i] == '.')
|
||||
{
|
||||
if (floatingPoint > 0.0f) break;
|
||||
|
||||
floatingPoint = 10.0f;
|
||||
continue;
|
||||
}
|
||||
if (floatingPoint > 0.0f)
|
||||
{
|
||||
value += (float)(text[i] - '0') / floatingPoint;
|
||||
floatingPoint *= 10.0f;
|
||||
}
|
||||
else
|
||||
value = value * 10.0f + (float)(text[i] - '0');
|
||||
}
|
||||
|
||||
return value * sign;
|
||||
}
|
||||
|
||||
#if defined(SUPPORT_TEXT_MANIPULATION)
|
||||
// Copy one string to another, returns bytes copied
|
||||
int TextCopy(char *dst, const char *src)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user