In Java: What is the difference between a variable of type int, and one of type double?

1

I was doing a program that tried to calculate pi, but java gave me an error:

  

Error: possible loss and conversion from double to int

I solved it by changing all my variables to the double type, but I was curious about the difference

    
asked by Gabriel Mation 04.11.2018 в 20:39
source

1 answer

1

The type double is a floating point data type, that is, it can store real numbers with decimals (up to a certain precision), such as 3.1415926537 or 1.0 , while that type int is an integer type and can only store numbers without decimals, such as 1 , 2 , 3 , etc.

That's why by assigning a double to a int , java alerts you. The free translation of the message would be something like:

  

Error: possible conversion with information loss from double to int

More information at java Primitive Data Types (in English)

    
answered by 04.11.2018 / 20:43
source