Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设 x = 2/3 和 n = 10
然后我想打印:.6666666666(10 个六,因为 n 是 10)
而不是 .6666666667 <- 我不想要那七个!!!!
您将如何在 C 或 C++ 中以这种方式打印?
C:
double foo = 2.0 / 3.0; printf("%.10f", floor(foo * pow(10, 10)) / pow(10, 10));
C++:
double foo = 2.0 / 3.0; std::cout << std::fixed << std::setprecision(10) << std::floor(foo * std::pow(10.0, 10.0)) / std::pow(10.0, 10.0);