function to convert string to float
This commit is contained in:
parent
a9ba51aa72
commit
49750f9ebf
|
|
@ -1481,6 +1481,7 @@ RLAPI const char *TextToUpper(const char *text); // Get upp
|
||||||
RLAPI const char *TextToLower(const char *text); // Get lower 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 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 (negative values not supported)
|
||||||
|
RLAPI float TextToFloat(const char *text); // Get float value from text (negative values not supported)
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Basic 3d Shapes Drawing Functions (Module: models)
|
// Basic 3d Shapes Drawing Functions (Module: models)
|
||||||
|
|
|
||||||
20
src/rtext.c
20
src/rtext.c
|
|
@ -1421,6 +1421,26 @@ int TextToInteger(const char *text)
|
||||||
return value*sign;
|
return value*sign;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float TextToFloat(const char *text) {
|
||||||
|
float value = 0;
|
||||||
|
float sign = 1;
|
||||||
|
|
||||||
|
if ((text[0] == '+') || (text[0] == '-')) {
|
||||||
|
if (text[0] == '-') sign = -1;
|
||||||
|
text++;
|
||||||
|
}
|
||||||
|
int i;
|
||||||
|
for (i = 0; ((text[i] >= '0') && (text[i] <= '9')); ++i) value = value * 10 + (float) (text[i] - '0');
|
||||||
|
if (text[i++] == '.') {
|
||||||
|
float divisor = 10;
|
||||||
|
for (; ((text[i] >= '0') && (text[i] <= '9')); ++i) {
|
||||||
|
value += (float) (text[i] - '0') / divisor;
|
||||||
|
divisor *= 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return value * sign;
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(SUPPORT_TEXT_MANIPULATION)
|
#if defined(SUPPORT_TEXT_MANIPULATION)
|
||||||
// Copy one string to another, returns bytes copied
|
// Copy one string to another, returns bytes copied
|
||||||
int TextCopy(char *dst, const char *src)
|
int TextCopy(char *dst, const char *src)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user