Created
October 23, 2011 17:46
-
-
Save Xjs/1307633 to your computer and use it in GitHub Desktop.
ftoa
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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