Write a function that mimics the behavior of "ftoa" function,
It should be defined as follows:
char* ftoa (float number, char* buffer, int base )
Example:
int n = 2.5;
char* buffer = new char[20];
ftoa(n,buffer,10);
cout<
Answers
Answered by
0
Answer:
void ftoa(float number, char* buffer, int base)
{
int ipart = (int)number;
float fpart = n - (float)ipart;
int i = intToStr(ipart, buffer, 0);
if (base != 0) {
buffer[i] = '.';
fpart = fpart * pow(10, base);
intToStr((int)fpart, buffer + i + 1, base);
}
}
Explanation:
The above function ftoa() will converts a floating-point/double number to a string.
buffer[i] = '.'; statement will add "." and get the value of fraction part.
Similar questions
Social Sciences,
5 months ago
Social Sciences,
5 months ago
History,
5 months ago
Math,
9 months ago
Math,
9 months ago
History,
1 year ago