精度 强制转换 浮点数

int main(){
char *a0="0.89";
char *a1="1.89";
char *a2="2.89";
char *a3="3.89";
char *a4="4.89";
char *a5="5.89";
char *a6="6.89";
char *a7="7.89";
char *a8="8.89";
char *a9="9.89";

long A0=atof(a0)*100;
long A1=atof(a1)*100;
long A2=atof(a2)*100;
long A3=atof(a3)*100;
long A4=atof(a4)*100;
long A5=atof(a5)*100;
long A6=atof(a6)*100;
long A7=atof(a7)*100;
long A8=atof(a8)*100;
long A9=atof(a9)*100;

printf("%.16lf\n",atof(a0));
printf("%.16lf\n",atof(a1));
printf("%.16lf\n",atof(a2));
printf("%.16lf\n",atof(a3));
printf("%.16lf\n",atof(a4));
printf("%.16lf\n",atof(a5));
printf("%.16lf\n",atof(a6));
printf("%.16lf\n",atof(a7));
printf("%.16lf\n",atof(a8));
printf("%.16lf\n",atof(a9));

printf("*******\n");

printf("%.16lf\n",atof(a0)*100);
printf("%.16lf\n",atof(a1)*100);
printf("%.16lf\n",atof(a2)*100);
printf("%.16lf\n",atof(a3)*100);
printf("%.16lf\n",atof(a4)*100);
printf("%.16lf\n",atof(a5)*100);
printf("%.16lf\n",atof(a6)*100);
printf("%.16lf\n",atof(a7)*100);
printf("%.16lf\n",atof(a8)*100);
printf("%.16lf\n",atof(a9)*100);

printf("*******\n");

printf("%ld\n",A0);
printf("%ld\n",A1);
printf("%ld\n",A2);
printf("%ld\n",A3);
printf("%ld\n",A4);
printf("%ld\n",A5);
printf("%ld\n",A6);
printf("%ld\n",A7);
printf("%ld\n",A8);
printf("%ld\n",A9);

}

0.8900000000000000
1.8899999999999999
2.8900000000000001
3.8900000000000001
4.8899999999999997
5.8899999999999997
6.8899999999999997
7.8899999999999997
8.8900000000000006
9.8900000000000006
*******
89.0000000000000000
189.0000000000000000
289.0000000000000000
389.0000000000000000
488.9999999999999432
589.0000000000000000
689.0000000000000000
789.0000000000000000
889.0000000000000000
989.0000000000000000
*******
89
189
289
389
488
589
689
789
889
989

3.89
4.89
5.89

1 11 52

111000111101011100001010001111010111000010100011110101110000

100位的表示

1110001111010111000010100011110101110000101000111101011100001010001111010111000010100011110101110000

3.89
11.111000111101011100001010001111010111000010100011110101110000
1.1111000111101011100001010001111010111000010100011110101110000*2^1

0

00000000001

1111000111101011100001010001111010111000010100011110

0000000000011111000111101011100001010001111010111000010100011110

4.89
1.00111000111101011100001010001111010111000010100011110101110000*2^2
0 00000000010 0011100011110101110000101000111101011100001010001111

5.89
1.01111000111101011100001010001111010111000010100011110101110000*2^2
0 00000000010 0111100011110101110000101000111101011100001010001111

3.8900000000000001
4.8899999999999997
5.8899999999999997

*100后，转为二进制，代表的值是：

389.0000000000000000
488.9999999999999432
589.0000000000000000

488.9999999999999432就是488

• 本文已收录于以下专栏：

举报原因： 您举报文章：精度 强制转换 浮点数 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)