0
    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

Kiotzu
  • 41
  • 8
  • 1
    possible duplicate of http://stackoverflow.com/questions/16369726/declaring-floats-why-default-type-double – Keale Oct 14 '15 at 06:06
  • related: http://stackoverflow.com/questions/3033137/representing-float-values-in-java http://stackoverflow.com/questions/14102955/java-why-do-you-need-to-specify-a-f-in-a-float-literal – Keale Oct 14 '15 at 06:07
  • duplicate of http://stackoverflow.com/questions/16369726/declaring-floats-why-default-type-double – T8Z Oct 14 '15 at 06:16
  • sorry, I didn't see that question. – Kiotzu Oct 14 '15 at 20:25

1 Answers1

4

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.

Eran
  • 387,369
  • 54
  • 702
  • 768