C中的整数到浮动转换

Nan*_* HE 3 c printf types

float f1 = 123.125;
int i1 = -150;

f1 = i1;    // integer to floating conversion
printf("%i assigned to an float produces %f\n", i1, f1);
Run Code Online (Sandbox Code Playgroud)

输出:

-150 assigned to an float produces -150.000000
Run Code Online (Sandbox Code Playgroud)

我的问题是为什么结果000000后面有6个零().而不是7或8或一些数字?

eph*_*ent 7

这就是做什么的printf.请参阅手册页,它说

f, F

double参数应转换为"[ - ] ddd.ddd"样式的十进制表示法,其中基数字符后面的位数等于精度规范.如果缺少精度,则应视为6 ; 如果精度明确为零且没有'#'标志,则不会出现基数字符.如果出现基数字符,则在其前面至少出现一个数字.低位数字应以实现定义的方式舍入.

(强调我的)

它与150如何在内存中表示为浮点数无关(事实上,它被提升为a double因为printf是varargs).