c++ float vs java float | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

c++ float vs java float

i heard C use 32|64-bit IEEE 754 system to atore float number like Java and JS but this example rejects it. https://code.sololearn.com/cn94Wypvi7MN/?ref=app https://code.sololearn.com/c43Y3AWX2Jji/?ref=app

1st Aug 2021, 7:12 PM
Mehran
Mehran - avatar
2 Answers
+ 3
Both C++ and Java use IEEE 754 system. Also C++ acts the same way, it just rounds the value on cout. This code will output ("not 0.3"): #include <iostream> using namespace std; int main() { if((0.1+0.2) == 0.3) cout <<"0.3"; else cout << "not 0.3"; }
1st Aug 2021, 11:11 PM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
+ 1
cout<< (0.1+0.2 == 0.30000000000000004);
3rd Aug 2021, 1:57 AM
zemiak