SUM Double 0 Type Field May Have Precision Issues After Decimal Point

This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: sum double 0类型字段会出现小数点后面精度问题

| username: Jjjjayson_zeng

【TiDB Usage Environment】Production Environment
【TiDB Version】v6.5.1
【Reproduction Path】Occurs during sum
【Encountered Problem: Phenomenon and Impact】
【Resource Configuration】Go to TiDB Dashboard - Cluster Info - Hosts and take a screenshot of this page
【Attachments: Screenshots/Logs/Monitoring】

| username: Jjjjayson_zeng | Original post link

When summing double type

| username: Billmay表妹 | Original post link

Yes, when using the SUM aggregate function to sum fields of type DOUBLE, precision issues may occur after the decimal point. This is because DOUBLE type data is stored in binary form in the computer, and binary cannot accurately represent certain decimal fractions, which may lead to precision errors during calculations.

To avoid this issue, you can use the DECIMAL type to store decimal values. The DECIMAL type can accurately represent decimal fractions and will not have precision errors during calculations. If you need to perform precise calculations on decimal values, it is recommended to use the DECIMAL type instead of the DOUBLE type.

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.