Pass floats as string literals to a methodTag(s): String/Number

Color c = new Color(0.1,0.2,0.4);
returns "Incompatible type for constructor. Explicit cast needed to convert double to int." even if the constructor Color (float r, float g, float b) is valid. That's because the compiler interprets numbers like 0.1 as double not float. You must use the suffixe "f" to indicate that the number is a float.
Color c = new Color(0.1f,0.2f,0.4f);



If you find this article useful, consider making a small donation
to show your support for this Web site and its content.

Written and compiled by Réal Gagnon ©1998-2012
[ home ]