Floating Point Numbers

Why in c++ (0.1 + 0.1) is not equal to 0.2 ??

Questions by mehulgala177   answers by mehulgala177

Showing Answers 1 - 2 of 2 Answers

The floating-point arithmetic in most computer languages is based on binary fractions (1/2, 1/4, 1/8, 1/16, ...) and not decimal fractions (1/10, 1/100, 1/1000, 1/1000,...)there is no ActionScript Number that is exactly equal to 0.1 because it require an infinite number of binary fractional bits.

  Was this answer useful?  Yes

moin khan

  • Sep 13th, 2013
 

It is obviously give 0.2 answer ...

Code
  1. #include <iostream>

  2. #include<stdio.h>

  3.  

  4. using namespace std;

  5.  

  6. int main()

  7. {

  8.     float a;

  9.     a=0.1+0.1;

  10.     printf("%f

  11. ",a);

  12.    cout<<a;

  13.    return 0;

  14. }

  15.  

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions