If I perform
97346822*3f, result is 2.9204048E8,
however
97346822*3.0 gives me 2.92040466E8.
Please explain.
The number 3.0
is the literal representation of a double
value (it's equivalent to 3.0d
), whereas 3.0f
is a float
value. The different precisions explain why you're getting different results - a double
is stored using 64-bits, a float
uses 32-bits.
97346822*3.0
will be treated as double
.
Based on oracle tutorial
The double data type is a double-precision 64-bit IEEE 754 floating point. Its range of values is beyond the scope of this discussion, but is specified in the Floating-Point Types, Formats, and Values section of the Java Language Specification. For decimal values, this data type is generally the default choice.
97346822*3f
will be treated as float
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With