程序没问题但是结果不对
程序代码:#define _STDC_WANT_LIB_EXT1_1
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <math.h>
#define number_count 3
int main(void)
{
double a = -1.15;
double temp = a;
char* bh_to_string = NULL;
int bf_length = 0;
int bh_length = 0;
int length = 0;
while (fabs(temp) - (int)fabs(temp) != 0)
{
bh_length++;
temp = temp * 10;
}
temp = fabs(a) - (int)fabs(a);
temp = pow(10,bh_length) * temp;
int x = (int)temp;
bh_length++;
bh_to_string = malloc(bh_length + 1);
bh_to_string[bh_length] = '\0';
while (temp >= 1)
{
bh_length--;
bh_to_string[bh_length] = (int)temp % 10 + '0';
temp = temp / 10;
}
bh_to_string[0] = '.';
printf("%s\n",bh_to_string);
return 0;
}
这个是个程序转换题,给一个指定的双精度,将小数点以后的数字转换成字符串形式输出,例如-1.15,字符串输出就应该是.15,但是我写的程序结果是.14。求大神帮帮忙









