Why whene write varible float give me erro like write float price =104.4; | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why whene write varible float give me erro like write float price =104.4;

16th Jun 2017, 11:37 PM
esraa ragab
5 Answers
+ 10
I suspect that declaring the variable in the function call is what is tripping you up. Try to separate the lines. A few other thoughts: It'd be much easier to answer questions if you'd indicate the language (since they all handle things a bit differently), if you would provide a true code snippet, and if you'd provide a bit more information about the error message.
17th Jun 2017, 12:18 AM
Jim
Jim - avatar
+ 3
Please specify the language.
17th Jun 2017, 12:05 AM
Rrestoring faith
Rrestoring faith - avatar
+ 3
If you do not specify the value type Java will assume a default value, which Java will by default use double for decimal numbers. Floats cannot be converted to double, so you receive an error. You can specify the value type to a float by adding an 'f' to the end of the value. Like this: float price = 104.4f; If you do not want to have to put the f at the end, you could just use a double instead. Like this: double price = 104.4;
17th Jun 2017, 12:25 AM
Rrestoring faith
Rrestoring faith - avatar
0
java
17th Jun 2017, 12:22 AM
esraa ragab
0
yes you are right this is the error like this exactally ,thank you for your help
17th Jun 2017, 12:28 AM
esraa ragab