简体   繁体   English

将double转换为float

[英]Converting a double to float

    class calc_Payroll

    private float hours;
    private float rate;
    private int hrsStr;
    float gross;

    calc_Payroll(float a, float b, float c, float d)
    {
    gross = hours + (hrsStr * 1.33) * rate;  //error here
    }

I'm confused as to where I have converted anything to a double? 我对将任何内容转换为双精度的地方感到困惑? but the error I am getting is 但是我得到的错误是

cannot covert double to float 无法掩盖双浮

1.33 is a double literal, and it causes the entire hours + (hrsStr * 1.33) * rate expression to return a double value, which can't be assigned to a float variable without an explicit cast. 1.33是一个double hours + (hrsStr * 1.33) * rate字面量,它使整个hours + (hrsStr * 1.33) * rate表达式返回一个double float值,如果没有显式hours + (hrsStr * 1.33) * rate ,则不能将其分配给float变量。

Change it to 1.33f for a float literal. 将其更改为1.33f以获取float文字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM