Wednesday, May 30, 2018

Floating-Point Literals using JAVA

Floating-point numbers represent decimal values with a fractional component. They
can be expressed in either standard or scientific notation. Standard notation consists
of a whole number component followed by a decimal point followed by a fractional
component. For example, 2.0, 3.14159, and 0.6667 represent valid standard-notation
floating-point numbers. Scientific notation uses a standard-notation, floating-point number
plus a suffix that specifies a power of 10 by which the number is to be multiplied. The
exponent is indicated by an E or e followed by a decimal number, which can be positive
or negative. Examples include 6.022E23, 314159E–05, and 2e+100.
Floating-point literals in Java default to double precision. To specify a float literal,
you must append an F or f to the constant. You can also explicitly specify a double literal
by appending a D or d. Doing so is, of course, redundant. The default double type
consumes 64 bits of storage, while the less-accurate float type requires only 32 bits.
banner
Previous Post
Next Post

0 comments: