In C++ float value being truncated from double

后端 未结 4 929
南旧
南旧 2021-01-27 22:59

I\'ve coded using float variables before and never had this problem.

float  a, b, subtotal, stx;
a=15.95;
b=24.95;
subtotal=a+b;
stx=subtotal*.07;

cout <         


        
4条回答
  •  南方客
    南方客 (楼主)
    2021-01-27 23:21

    15.95 is treated as a double no matter what it is assigned to; the variable's type only affects what value it ends up holding, not what you try to assign to it. The right side of an assignment is always evaluated first.

提交回复
热议问题