c语言中 double

jjjyu123 2010-06-08 10:18:00
double x=123.45123451234512345
printf("%.17\n",x);

打印出来的是123.4513451234512402
谁能跟我解释下为什么会打印出这个值最后三位它是怎么处理的?
...全文
510 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
pengzhixi 2010-06-08
  • 打赏
  • 举报
回复
这点误差允许的
ziyoushouhuzhe 2010-06-08
  • 打赏
  • 举报
回复
写个高精度吧
konta 2010-06-08
  • 打赏
  • 举报
回复
When a double is demoted to float,a long double is demoted to double or float, or a value being represented in greater precision and range than required by its semantic type (see 6.3.1.8) is explicitly converted to its semantic type, if the value being
converted can be represented exactly in the new type, it is unchanged. If the value being converted is in the range of values that can be represented but cannot be represented exactly, the result is either the nearest higher or nearest lower representable value, chosen in an implementation-defined manner. If the value being converted is outside the range of values that can be represented, the behavior is undefined.
向立天 2010-06-08
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 z569362161 的回复:]
引用 4 楼 jjjyu123 的回复:
我知道double是15位精度 但我硬让它打印17位的话 后面两位是怎么处理的?


问CPU去
[/Quote]
呵呵
确实
应该是随机的
z569362161 2010-06-08
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 jjjyu123 的回复:]
我知道double是15位精度 但我硬让它打印17位的话 后面两位是怎么处理的?
[/Quote]

问CPU去
建鼎呓语 2010-06-08
  • 打赏
  • 举报
回复
你让他存入一个值,然后他就存入他能存入的最接近的值,然后打印出来的就有可能不绝对是你设置的那个值了。
jjjyu123 2010-06-08
  • 打赏
  • 举报
回复
我知道double是15位精度 但我硬让它打印17位的话 后面两位是怎么处理的?
happytang 2010-06-08
  • 打赏
  • 举报
回复
处理浮点数精度问题,不同处理器是不一样的
z569362161 2010-06-08
  • 打赏
  • 举报
回复
double的精度是15位有效数字,取值范围是10的-308次方到10的308次方,double占用8字节空间。
z569362161 2010-06-08
  • 打赏
  • 举报
回复
精度问题

69,371

社区成员

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

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