0

It is necessary to declare the variable as "float"?

In python not is necesary so, im cofuse.

10th Oct 2016, 4:53 AM
Andres Camilo Cortes
Andres Camilo Cortes - avatar
3 Answers
+ 3
Depends on the language... some language demand the type to be declared or else they will not compile/run.. in other languages like python is not needed because it will try to guess the correct type from the value that you assign to the variable at first. Anyway, you have ways to make shure python is storing the value in the variable as a float: i.e. using the decimal point (even when its not needed) when storing a number in a variable, using typecasting (yourVar = float(someValue)), storing the result from a operation that you know it will return a float, Etc.
10th Oct 2016, 6:03 AM
Nelson Urbina
Nelson Urbina - avatar
+ 1
in c++ of course it is necessary.
10th Oct 2016, 5:03 AM
Andresgallo10
Andresgallo10 - avatar
+ 1
If you are working with rational numbers like pi or e or 1/3 or any other yes, you should. If you don't do it, the program will take the integer part (in pi will take the 3, in 1/3 will take 0...).
10th Oct 2016, 5:03 AM
German Martinez
German Martinez - avatar