关于float 转化成字符串之后,打印出现-1.#IND00或者-1.#J的问题

wanghi 2015-12-22 09:27:44

typedef struct
{
float score1;
float score2;
float score3;
char id[10];
char name[20];
}zzz_t;

zzz_t human[60];
char str[100] = {'\0'};
char strtemp[100] = {'\0'};

然后从数据库获取数据之后,打印出来
sprintf(str,"%.2f,%.2f",human[0].score3,human[0].score2);
sprintf(strtemp,"%f,%f",human[0].score3,human[0].score2);
printf(" %d %d \n",sizeof(zzz_t),sizeof(float));
printf(" %.2f %.2f \n",human[0].score3,human[0].score2);
printf(" %s \n",str);
printf(" %s \n",strtemp);
打印结果
44 4
82.20 67.30
-1.#J 67.30
-1.#IND00 67.30

就 human[0].score3 这一个地方出现问题,其他都打印正常








...全文
277 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wanghi 2015-12-27
  • 打赏
  • 举报
回复
算了,不研究了 sprintf(str,"%.2f",human[0].score3); sprintf(strtemp,"%.2f,%.2f",human[0].score2,human[0].score1); strcat(str,strtemp); printf(str); 这样就没问题,奇怪 先结贴
paschen 2015-12-25
  • 打赏
  • 举报
回复
浮点数可能除以了0
begodliker 2015-12-25
  • 打赏
  • 举报
回复
应该是没有获取到human[0].score3,而你的human又没有初始化,所以才会输出错误
赵4老师 2015-12-23
  • 打赏
  • 举报
回复
To set a breakpoint when a variable human[0].score3 changes value From the Edit menu, click Breakpoints. Click the Data tab of the Breakpoints dialog box. In the Expression text box, type the name of the variable human[0].score3. Click OK to set the breakpoint.
gh_99 2015-12-22
  • 打赏
  • 举报
回复
把数据库获取数据原先赋给human[0].score3的值赋给human[0].score2,看看是否正常. 正常则是你数据库获取数据有问题或是对human[0].score3操作有问题.

70,020

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧