Is there any library function in KEIL C which converts a floating point into string. If not can somebody give the appropriate code.
maybe you can write his code; for example;
- specify your string array
unsigned char str_float[20];
. -find the maximum divider, and number of digit at left side of comma
if(float_number<10) {divider=1;digit=1} if(float_number<100) {divider=10;digit=2} if(float_number<1000) {divider=100;digit=3} ... etc
.
-and how much digit you want at right side of comma, for example you want two digit from right side of comma, multiply with 100 and convert to long
long_value=(unsigned long)float_value*100; digit+=2; divider*=100;
. --and now start take digits
str_float[digit+2]="\0"; while(digit>2){ str_float[digit+1]=long_number/(divider) + "0" ; long_number/=10; divider/=10; digit--; } str_float[2]=","; str_float[1]=long_number/10+"0"; str_float[0]=long_number%10+"0";
i know this code very weak, powerless, i write this only for give an idea. for example float_value=0,54 this code fails
maybe you can write his code;
Why reinvent the wheel ?
sprintf() does the job.
sprintf() (and scanf()) are big and slow. Occasionally, for some limited applications, it can be worthwhile to write custom parsing or output that doesn't have to handle all of the data types and formatting options of the library routines.
But it's rarely worth the effort.
why worry about "sprintf() (and scanf()) are big and slow" once you have already lost any illusion of performance by using floating point with a '51?
Erik
If scanf() is big and slow, check for the availability of atof() or strtod().
If sprintf() is big and slow, check for the availability of ecvt(), fcvt() or gcvt() functions.
The scanf() and sprintf() functions are normally never implemented monolitically. They normally makes use of helper functions like the above suggestions, and they may be used directly.
By the way, don't stop using scanf() because it is large or slow. Stop using it because it is quite lousy. It has a tendancy to be dangerous. It has a tendancy to leave data in the input buffer. It only returns the number of converted arguments - not the location of the first erroneous character. It isn't always obvious how to write the formatting string, to handle non-convertable data in the input string.
"check for the availability of atof() or strtod() ... ecvt(), fcvt() or gcvt"
www.google.com/codesearch