+ 1

Float or integer

0.0 is double or float. What about 0? is 0 an integer ? Is 0 a float?

1st Oct 2024, 1:34 PM
Oliver Pasaribu
4 ответов
+ 6
0.0 C/C++, Java, C#: double Python, JavaScript: float 0 C/C++, Python, Java, C#: integer JavaScript: float* If you want to make 0.0 explicitly float instead of double in C/C++, Java, C# then use 0.0f. If you want to make 0 explicitly long integer in C/C++, Java, C# then use 0L. * - JavaScript has only one number type, which is equivalent to a floating point type.
1st Oct 2024, 2:29 PM
Brian
Brian - avatar
+ 4
It depends on the context. You have not provided any context. You can print the data type and find out.
1st Oct 2024, 1:41 PM
Lisa
Lisa - avatar
+ 3
Oliver Pasaribu this could be either ... floats are generally precise within 7 decimal points doubles are generally precise within 15 decimal points I usually depending on the language go with double.
1st Oct 2024, 1:45 PM
BroFar
BroFar - avatar
+ 1
0 is many things like nullptr, NULL, false in C++. maybe it is like that in Java but Java is strict and you should add .f to make it float or widening conversion. If you do not try it, then 0 is default to integer
1st Oct 2024, 10:25 PM
Sharpneli
Sharpneli - avatar