Home > Back-end > Guarantee the accuracy of the decimal precision spintf format type double?
Guarantee the accuracy of the decimal precision spintf format type double?
Time:01-05
Such as char [256] a={0 x00}; Sprintf (a, "12 f % %., 13082.8725); I hope to get the 13082.872500000000 Rather than 13082.872599999990 I ask bosses should to do,
CodePudding user response:
Floating-point format http://bbs.csdn.net/topics/390676437
CodePudding user response:
There is no universal method, can only hope that you use the library has a higher conversion accuracy, in my tests, the only 64 compiler can correct converted to c + + Builder 13082.872500000000 Other c + + compiler, vc + +, Intel c + +, GCC, including c + + Builder 32-bit compiler, conversion is 13082.872499999999
CodePudding user response:
Floating point precision limit 13082.8725 endures memory is 13082.872599999990, so the fault is not in the sprintf, originally is such If really need such a high precision, I know there are BigDecimal in Java, c + + can look for a third-party library Or write their own structure, the decimal segmented into several integers