+ 1

Whether float can be use in switch condition?

12th Jan 2020, 12:51 AM
Parkavi S
8 Respostas
+ 4
No.
12th Jan 2020, 12:54 AM
HonFu
HonFu - avatar
+ 3
You can pretend by rounding to tenths such as: switch ((int)round(value*10.0)) { case 0: //0.0 case 10: //1.0 }
12th Jan 2020, 4:18 AM
John Wells
John Wells - avatar
+ 2
I have no idea. Maybe because of the typical unpreciseness of float? Maybe someone else knows.
12th Jan 2020, 1:12 AM
HonFu
HonFu - avatar
+ 1
Why we can't use float in switch
12th Jan 2020, 1:09 AM
Parkavi S
+ 1
Ok 😊
12th Jan 2020, 1:14 AM
Parkavi S
+ 1
Round off first
12th Jan 2020, 8:14 AM
Huzaifa Khilawala
Huzaifa Khilawala - avatar