Loading...
Java

Floating Point Literals

Floating point literals is by default double type. But it can be explicitly as float type by suffixing with f or F.
Example:
float f=123.546; //(invalid)
float f=123.546f; //(valid)
double d=123.546; //(valid)

Floating point literals can also specify as double type by suffixing with d or D.
Example:
double d=123.546D;

Floating point literals can only be specified in decimal form, but not in octal or hexa decimal forms.
Example:
double d=123.546; //(valid)
double d=0123.435; //(valid but it is treated as decimal value but not octal)
double d=0x123.435; //(invalid)

Valid floating points declarations
1. float f=123.435; //(invalid)
2. float f=123.435D; //(invalid)
3. double d=0x123.435; //(invalid)
4. double d=0xColour; //(valid)
5. double d=0xCode; //(valid)


Leave a Reply

Your email address will not be published. Required fields are marked *