双精度数字。 [英] Double precision numbers.

查看:77
本文介绍了双精度数字。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

只需查看此代码:


#include< stdio.h>

int main()

{

加倍a,b;

scanf("%lf",& a);

scanf("%lf",& b);

printf(" \ nNumber a:%0.16lf",a);

printf(" ; \ nNumber b:%0.16lf",b);

printf(" \\\
Difference:%0.16lf\\\
",(ab));

返回0;

}


输出

------

[alagu @localhost十进制] $ ./decimal

12.3333

11.1111


编号a:12.3332999999999999

编号b:11.1111000000000004

差异:1.2221999999999991

--------------------------- --------

我们想要一个干净的数字,如12.3333而不是

12.3332999.这是什么原因这个

和反正有没有避免这种情况?我们想要十进制

点是准确的。怎么做?


谢谢s提前,

问候,

Allagappan M

Hello everyone,
Just check this code:

#include<stdio.h>
int main()
{
double a,b;
scanf("%lf",&a);
scanf("%lf",&b);
printf("\nNumber a: %0.16lf",a);
printf("\nNumber b: %0.16lf",b);
printf("\nDifference:%0.16lf\n",(a-b));
return 0;
}

Output
------
[alagu@localhost decimal]$ ./decimal
12.3333
11.1111

Number a: 12.3332999999999995
Number b: 11.1111000000000004
Difference:1.2221999999999991
-----------------------------------
We wanted a clean number like 12.3333 and not
12.3332999.What is the reason for this
and is there anyway to avoid this?We want decimal
points to be exact.How to do it?

Thanks in advance,
Regards,
Allagappan M

推荐答案

。 /十进制

12.3333

11.1111


编号a:12.3332999999999995

编号b:11.1111000000000004

差异:1.2221999999999991

--------------------------------- -

我们想要一个干净的数字,比如12.3333而不是

12.3332999.这是什么原因这个

并且无论如何要避免这个?我们想要十进制

点是准确的。怎么做?

提前谢谢,

问候,

Allagappan M

./decimal
12.3333
11.1111

Number a: 12.3332999999999995
Number b: 11.1111000000000004
Difference:1.2221999999999991
-----------------------------------
We wanted a clean number like 12.3333 and not
12.3332999.What is the reason for this
and is there anyway to avoid this?We want decimal
points to be exact.How to do it?

Thanks in advance,
Regards,
Allagappan M


实际上有一个非常双的数字,附加精度。很长

double会有更高的精度,而float会有更低的精度。

为了避免你面临的问题,你需要设置你自己的数据

结构代表你需要的精度。


问候,

Bhuwan Chopra

Actually with very double number there is a precision attached. long
double will have more precision while float will have a less precision.
To avoid the problem you facing you got to device your own data
structure to represent precision you require.

Regards,
Bhuwan Chopra


> [alagu @ localhost decimal]
> [alagu@localhost decimal]


这篇关于双精度数字。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆