0

Correct way to declare floating literal

always add f or F next to the value of variable so that compiler would understand that this is a floating literal otherwise it will take any number having point as a double by default https://code.sololearn.com/cZyAYzg7D925/?ref=app

10th Aug 2017, 2:24 PM
AMIT KUMAR
AMIT KUMAR - avatar
4 Respostas
+ 3
@AMIT KUMAR I didn't have any problem in changing all occurence of 2.6 in your code to 2.6f even in code playground...
11th Aug 2017, 12:52 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 1
But then again, it's not a very good idea to use == with a floating point number in the first place :P
10th Aug 2017, 2:35 PM
Dennis
Dennis - avatar
0
try float n=2.6f it won't work here but definitely on other compilers like turboc++ ,dev C++ etc.
10th Aug 2017, 2:25 PM
AMIT KUMAR
AMIT KUMAR - avatar
0
@Dennis I know but here I just want to explain that your number will no longer be the same while performing any other operations on that floating number, it's just a logical error which could make your program less accurate so we better use f or F next to the numbers to correct it.
11th Aug 2017, 9:11 AM
AMIT KUMAR
AMIT KUMAR - avatar