c:math:fmtchg

C++ Reference

=============================================================== Purpose: Change a float number to a string with n numbers proceeding the dot and n numbers come after the dot. ===============================================================// void fmtchg(float a,char *str,int n,int m) {

int i,j,ctr,sign;long d;
char c,*tmp;
ctr=0;tmp=str;sign=0;
if (a < 0.0) {sign=-1;a=-a;ctr++;}
for (i=0;i < m;i++) a=a*10.0;d=a+0.5;i=0;
while(1) {
	if (d == 0L && i > m) break;
	j=d%10L;*tmp++='0'+j;d/=10L;i++;if (++ctr >= n) break;
	if (i == m) {*tmp++='.';if (++ctr >= n) break;}
}

if (sign == -1) *tmp++='-';

while (ctr++ < n) *tmp++=' ';*tmp='\0';
for (i=0;i < n/2;i++) {
	c=*(str+i);*(str+i)=*(tmp-i-1);*(tmp-i-1)=c;
} 

}