Added a section called "Casting". Details on how data types can be stored in other data types. (#23881)
* Added a section called "Casting" * Reordered section, fixed typo
This commit is contained in:
committed by
Manish Giri
parent
7f00161e60
commit
61b6f1e19e
@ -110,7 +110,7 @@ double data type is a double-precision 64-bit [IEEE 754 floating point](http://s
|
||||
Default value: 0.0d.
|
||||
|
||||
Example: double d1 = 123.400778;
|
||||
|
||||
|
||||
## Character:
|
||||
|
||||
We use this data type to store characters. This is not the same as the char in C/C++. Java uses a `UNICODE`, internationally accepted character set. Char in Java is 16bits long while that in C/C++ is 8bits.
|
||||
@ -197,3 +197,19 @@ Output:
|
||||
```
|
||||
10198442
|
||||
```
|
||||
|
||||
### Casting
|
||||
|
||||
It is also important to note that it is possible to store different data types into one another. However, you would have to let the compiler know that you have acknowledge the possible loss of data by casting the variable.
|
||||
|
||||
For example:
|
||||
```java
|
||||
double d = 1.23
|
||||
|
||||
int i = (int)d;
|
||||
System.out.println(i);
|
||||
```
|
||||
Output:
|
||||
```
|
||||
1
|
||||
```
|
||||
|
Reference in New Issue
Block a user