A double can store more decimal places than a float. This means that
if convert a double to a float we will lose precision - i.e. the
number will be less precise.
1. [ C# ] Cannot convert a float to a double
We cannot even compile a program that might involve a loss of precision. Attempting to (implicitly) convert a double to a float will cause a compile error such as:
Demo.java:4: possible loss of precision found : double required: floatWe should do one of the following:
- Explicitly cast from double to float:
float d = (float)3.8;
- Use
fto indicate that the literal is afloatnot adouble
2. [ C# ] Problems with Round
This is an issue with Java