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

CodePudding user response:

refer to the second floor early play big play nuclear 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

Thank you, I look at ah, is really trouble you

CodePudding user response:

The
reference 3 floor Chgooo 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, decimal section can save for a few integer

Defined directly, and then print out is right, may be required too many decimal places,

CodePudding user response:

reference 1/f, zhao teacher reply:
floating-point format http://bbs.csdn.net/topics/390676437

Ok, thank you, I see
  • Related