The language will not implicitly perform the conversion, because this leads to a loss of accuracy. However, you can explicitly perform the conversion using cast:
myTotal = (float)( (quarters * .25) + (dimes * .10) + (nickels * .05) + (pennies * .01) );
In this case, you know that you are not dealing with astronomical quantities or exquisitely high precision, so this should be good.
You can also prevent automatic promotion of values twice, by specifying floating-point letters instead of doubling:
myTotal = (quarters * .25F) + (dimes * .10F) + (nickels * .05F) + (pennies * .01F);
... int variables will be assigned the float value for the add operation, so as a result you will get a float instead of a double type.
source share