使用boost/multiprecision/cpp_dec_float.hpp
#include <boost/multiprecision/cpp_dec_float.hpp> using boost::multiprecision::number; using boost::multiprecision::cpp_dec_float_50; int main() { cpp_dec_float_50 v1("5726.867366095"); // 为防止精度丢失,只能以字符串形式赋值, cpp_dec_float_50 v2("5837.754018494999"); // 否则就是把错误的值赋给了对象,初值就错了 const int64_t N = pow(10, 8); double newV1 = (int64_t)round(v1 * N) / double(N); double newV2 = (int64_t)round(v2 * N) / double(N); printf("%.8f\n", newV1); printf("%.8f\n", newV2); }
标签:multiprecision,double,截取,float,c++,cpp,dec,boost From: https://www.cnblogs.com/zl1991/p/18144697