Converting SQL FLOAT to SQL INT, lost data

前端 未结 2 1391
渐次进展
渐次进展 2021-01-17 22:05

I\'m having some problems with converting some data stored in a FLOAT datatype to data stored in an INT datatype. The below example illustrates my problem:

D         


        
相关标签:
2条回答
  • 2021-01-17 22:44

    This is common behaviour for float data type due to specificity of float on computers. Use decimal (number) data type with fixed digits after decimal point. For example, decimal(10, 6).

    0 讨论(0)
  • 2021-01-17 23:11

    This is the classic (int)((0.1+0.7)*10) problem. Because floats have arbitrary precision some data loss when casting to int is possible even for very simple cases.

    Use ROUND(weight * 1000000.0, 0) instead.

    0 讨论(0)
提交回复
热议问题