0

i am taking input in double up to 2 decimal place long and then multiplying it with 100 and storing in int .

double s;
cin>>s;
int p=s*100;
cout<<p;

however when i input a number say 285.65 i am getting a output of 28564. I cannot figure out why it is being truncated.

Matt Olson
  • 409
  • 5
  • 13
shivam
  • 11
  • 1
  • 3
    Check [Is floating point math broken?](http://stackoverflow.com/questions/588004/is-floating-point-math-broken) please. – πάντα ῥεῖ Sep 18 '15 at 17:52
  • 1
    http://stackoverflow.com/questions/18361261/losing-double-precision-when-multiplying-by-multiple-of-10 or http://stackoverflow.com/questions/6041295/multiplication-of-double-with-integer-precision or ... – hlscalon Sep 18 '15 at 17:56
  • 1
    This is not a duplicate of the linked question ("Is floating point math broken?"), which is about pure floating-point arithmetic. But it _is_ a duplicate of the questions that @old_mountain links to. – TonyK Sep 18 '15 at 18:45

0 Answers0