Kiotzu
Kiotzu

Reputation: 41

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

Upvotes: 0

Views: 148

Answers (1)

Eran
Eran

Reputation: 393821

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.

Change it to 1.33f for a float literal.

Upvotes: 4

Related Questions