what is the difference between 'Float a = 3f' and 'Float a = 3.0' in java?

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.

What Is The Difference Between A "Respirator" And A "Ventilator , Many of us know that both respirators and ventilators deal with breathing in some way, but what are their differences? Can they be used interchangeably? Difference between Coronavirus and SARS (). Coronavirus Vs. SARS Coronavirus is a viral respiratory illness that is caused by the virus 2019-nCoV.

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.

What's the difference between a pandemic, an epidemic, endemic , While conversational use of these words might not require precise definitions, knowing the difference is important to help you better understand  What is the difference between == and === in JavaScript? I have also seen != and !== operators. Are there more such operators? This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question. == is === with type converting (aka coercion).

These are findings related to this question and my answer to same.

While 3.0 and 3f both have the same value when put into floating point values, the actual value is used as working memory for the floating point operation. The internal values that are part of the multiplication do not fit into the floating point value themselves and are modified, resulting in a difference of 14.0 between the obtained results.

What is the difference between isolation and quarantine?, What is the difference between isolation and quarantine? Isolation and quarantine are public health practices used to protect the public by preventing exposure to  Difference Between has a large knowledge base and deal with differences between popular terms, technologies, things and anything to everything.

There is a concept called as Numeric promotion in Java

Numeric promotions are used to convert the operands(of an operation like multiplication, etc) of a numeric operator to a common type(smaller numeric type to a larger numeric type among the 2 datatypes of operands) to perform a specific operation

So in the example given by you, for 97346822*3f since the 3f is a float value so the floating point operation is done and the result is of float type.

But 3.0 is a double type which has higher range and precision which causes the results to vary

So the value of 3.0 and 3f are same, but when these values are used in a numeric operation then the result will vary based on the datatype of the other operand

Epidemic vs. Pandemic, What Is the Difference Between an , While casual use of epidemic may not require such nuance, it's important to know the differences between these two terms (and similar ones like outbreak and  The names Great Britain and United Kingdom are often used interchangeably. However, they are not actually synonymous. The reason for the two names, and the difference between them, has to do with the expansive history of the British Isles. Be on the lookout for your Britannica newsletter to get

Dementia vs. Alzheimer's Disease: What Is the Difference?, What is the difference between Alzheimer's and dementia? Get an overview of each and learn about early symptoms, risk factors, diagnosis and treatment. There are two types of articles – definite (the) and indefinite (a and an). The definite article refers to some specific object or some specific person. An indefinite article refers to a non-specific object or person. Both articles must be followed by a noun or an adjective and a noun. While “the” can be used for singular or plural nouns

Pandemic vs. Epidemic: What is the Difference?, What is the difference between an epidemic and a pandemic? Epidemic vs. Pandemic. An epidemic is defined as “an outbreak of disease that  The Difference Between .com, .net, .org and Why We’re About To See Many More Top-Level Domains. Chris Hoffman @chrisbhoffman October 15, 2012, 6:00am EDT

What's the Difference Between Great Britain and the United , The reason for the two names, and the difference between them, has to do with the expansive history of the British Isles. The British Isles are a group of islands off  Type 1 and type 2 diabetes may have similar names, but they are different diseases with unique causes. Causes of type 1 diabetes. The body’s immune system is responsible for fighting off foreign

Comments
  • The others have answered your question about the differing results. But I should note that the declaration you put in the title, Float a = 3.0 (or float a = 3.0), will be rejected by the compiler because 3.0 is treated as a double and it doesn't like you forcing it into a variable with lower precision (without an explicit type cast).
  • Why are the questions in the title and body different?
  • You need to know that float is not the same as Float which is not the same as double. Once you realise that the type actually matters, it is no surprise the answers are different.
  • 3.0 is exactly representable in both float and double, so there will be no difference for that particular case.
  • @Patricia: Correct, but the result of 97346822*3 is not exactly representable in a float.