Advertisement
Guest User

Untitled

a guest
May 26th, 2015
1,354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. /* float to string
  2.  * f is the float to turn into a string
  3.  * p is the precision (number of decimals)
  4.  * return a string representation of the float.
  5.  */
  6. char *f2s(float f, int p){
  7.   char * pBuff;                         // use to remember which part of the buffer to use for dtostrf
  8.   const int iSize = 10;                 // number of bufffers, one for each float before wrapping around
  9.   static char sBuff[iSize][20];         // space for 20 characters including NULL terminator for each float
  10.   static int iCount = 0;                // keep a tab of next place in sBuff to use
  11.   pBuff = sBuff[iCount];                // use this buffer
  12.   if(iCount >= iSize -1){               // check for wrap
  13.     iCount = 0;                         // if wrapping start again and reset
  14.   }
  15.   else{
  16.     iCount++;                           // advance the counter
  17.   }
  18.   return dtostrf(f, 0, p, pBuff);       // call the library function
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement