Configuration

Night mode

Casting

Java Basics Course

Engineers From These Top Companies and Universities Trust EXLskills

1M+ Professionals | 100+ Institutions

This is the EXLskills free and open-source Java Basics Course. It guides learners via explanation, demonstration, and thorough practice, from no more than a basic understanding of Java, to a moderate level of essential coding proficiency.

Is this course FREE?

Yes, this a 100% free course that you can contribute to on GitHub here!

We just converted the double value 15.23 into an integer, which left only the whole number and the decimal places to be cut off. There is no rounding, it just ignores the numbers after the decimal point during casting. When you convert an int to a double, a decimal point will be added to match with the structure of a double. For example, double varOne = (double) 15; assigns 15.0 to varOne.

Even though it is possible to convert an int to a double without casting, it is best practice to always use casting for precision and thorough logic. Also, be careful with the loss of precision when converting data types. i.e. losing decimal points is losing precision.