Skip to content

Instantly share code, notes, and snippets.

@Xjs
Created October 23, 2011 17:46
Show Gist options
  • Save Xjs/1307633 to your computer and use it in GitHub Desktop.
Save Xjs/1307633 to your computer and use it in GitHub Desktop.
ftoa
void ftoa(double f, char *output)
{
int m = log10(f);
int digit;
double precision = .0001;
while (f > 0 + precision)
{
double weight = pow(10.0, m);
digit = floor(f / weight);
f -= (digit * weight);
*(output++)= '0' + digit;
if (m == 0)
*(output++) = '.';
m--;
}
*(output) = '\0';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment