Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* float to string
- * f is the float to turn into a string
- * p is the precision (number of decimals)
- * return a string representation of the float.
- */
- char *f2s(float f, int p){
- char * pBuff; // use to remember which part of the buffer to use for dtostrf
- const int iSize = 10; // number of bufffers, one for each float before wrapping around
- static char sBuff[iSize][20]; // space for 20 characters including NULL terminator for each float
- static int iCount = 0; // keep a tab of next place in sBuff to use
- pBuff = sBuff[iCount]; // use this buffer
- if(iCount >= iSize -1){ // check for wrap
- iCount = 0; // if wrapping start again and reset
- }
- else{
- iCount++; // advance the counter
- }
- return dtostrf(f, 0, p, pBuff); // call the library function
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement