C++の次のコードを動かすと1974と1973という異なる結果が得られます(前者が正しいです)。内部では1973.999999...という値になってるのではと思っているのですが、原因の分かる方いらっしゃらないでしょうか。
C++
1// This file is a "Hello, world!" in C++ language by GCC for wandbox. 2#include <iostream> 3#include <cstdlib> 4 5int main() 6{ 7 double n=0.2820; 8 double m=7000; 9 std::cout<<n*m<<std::endl; 10 std::cout<<int(n*m)<<std::endl; 11} 12 13// GCC reference: 14// https://gcc.gnu.org/ 15 16// C++ language references: 17// https://cppreference.com/ 18// https://isocpp.org/ 19// http://www.open-std.org/jtc1/sc22/wg21/ 20 21// Boost libraries references: 22// https://www.boost.org/doc/ 23
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。