65,189
社区成员




#include <stdio.h>
double d1 = 1235.2;
double d2 = 10.6;
double d3;
int main() {
d3=d1-d2;
printf("%lf\n",d3);
printf("%.15lf\n",d3);
printf("%lg\n",d3);
printf("\n");
d3=1224.5999999999999;
printf("%lf\n",d3);
printf("%.15lf\n",d3);
printf("%lg\n",d3);
return 0;
}
//1224.600000
//1224.600000000000100
//1224.6
//
//1224.600000
//1224.599999999999900
//1224.6
//
不要迷信书、考题、老师、回帖;
要迷信CPU、编译器、调试器、运行结果。
并请结合“盲人摸太阳”和“驾船出海时一定只带一个指南针。”加以理解。
任何理论、权威、传说、真理、标准、解释、想象、知识……都比不上摆在眼前的事实!
有人说一套做一套,你相信他说的还是相信他做的?
其实严格来说这个世界上古往今来所有人都是说一套做一套,不是吗?
不要写连自己也预测不了结果的代码!
作为一个C程序员,对
scanf,sscanf,fscanf
printf,sprintf,fprintf
这类函数的用法,还是要做到“拳不离手,曲不离口”的。
f double Signed value having the form [ – ]dddd.dddd, where dddd is one or more decimal digits. The number of digits before the decimal point depends on the magnitude of the number, and the number of digits after the decimal point depends on the requested precision.
g double Signed value printed in f or e format, whichever is more compact for the given value and precision. The e format is used only when the exponent of the value is less than –4 or greater than or equal to the precision argument. Trailing zeros are truncated, and the decimal point appears only if one or more digits follow it.
f The precision value specifies the number of digits after the decimal point. If a decimal point appears, at least one digit appears before it. The value is rounded to the appropriate number of digits. Default precision is 6; if precision is 0, or if the period (.) appears without a number following it, no decimal point is printed.
g, G The precision specifies the maximum number of significant digits printed. Six significant digits are printed, with any trailing zeros truncated.