1 year ago

#365817

test-img

user_289389232

Repeating decimal being represented as 1?

I am new to C++ and when writing a program, I've found that two equivalent expressions are returning different values when I call the floor function. I assume that it has something to do with how the computer stores values after performing mathematical operations but I'm not completely sure. I've written the two expressions below and was wondering if there is any way to work around this (i.e. get the first floor call to return 1 rather than 0 without using ceil).?

cout << floor((((((3661. / 3600.) - 1) * 60.) - 1) * 60.)) << endl; // returns 0
cout << floor((1. / 60.) * 60.) << endl; // returns 1

c++

decimal

floor

0 Answers

Your Answer

Accepted video resources