0
#include <bits/stdc++.h>

using namespace std;

int main() {
  cout << fixed << setprecision(10);
  double p;
  cin >> p;
  cout << p << " ";
  p = p * 1000;
  cout << p << " ";
  int r = floor(p);
  cout << r << endl;
  return 0;
}

input: 1036.456

output: 1036.4560000000 1036455.9999999999 1036455

I'm using the online compiler on ideone.

Why is the second number 1036455.9999999999and not1036456` as I would expect?

dtell
  • 2,231
  • 1
  • 10
  • 29
ram singh
  • 3
  • 2
  • The usual memory format of a double is [IEEE 754 double-precision binary floating-point format: binary64](https://en.wikipedia.org/wiki/Double-precision_floating-point_format). The double value `1036.456` is stored in memory as `2^10 * 1.0121640625`. – Thomas Sablik Nov 02 '20 at 14:27

0 Answers0