开发者

divide drops remainder in DB2 SQL

So I'm dividing an integer by a decimal, and storing the re开发者_JAVA百科sult in a decimal column. However, it always drops the fractional component(the part after the decimal point). If I multiply the result by 10 or 100 I get a more accurate result, but dividing again drops the fractional part again.

The two fields I've inserted into were a precision 5, scale 0 decimal and a precision 5, scale 3 decimal.

I've also tried casting the integer into a decimal and that doesn't make a difference, neither does multiplying by 1.0.

I'm out of ideas or tricks to try.

Thanks, Buzkie


Turns out I was casting incorrectly. After doing using the correct format

CAST(int AS DECIMAL(5,3))

it worked. I had left off the precision and scale before.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜