Sorry for not publishing a post for weeks, little bit busy with my final year examination.
Okay let's get to work, today I'm going to show you how to use decimal values in Java. Previously
we worked with byte, short, int, long all these data types are using for integer values. In Java we can use "float" and "double" to deal with decimal values. Read more about data types in Java Data Types In Java.
Here I'm going to show how to work with "float" data type.
Let's use "float" in code,
Here you can see assigned value for "float f" is 1 but printed output is 1.0, this happens because float use to represent decimal values. No big deal.
Let's assign 1.0 to "float f"
To fix this error we have to type a "F" or "f" after the assigned value,
Let's write a code to add two float values together,
Another ways to do this addition,
No comments:
Post a Comment