开发者

Restricting the length of a double field in SQL

开发者 https://www.devze.com 2023-01-06 02:53 出处:网络
I don´t have a field as such, but I am making a new field which is the result dividing an existing开发者_如何转开发 field, i.e. cost/1.15

I don´t have a field as such, but I am making a new field which is the result dividing an existing开发者_如何转开发 field, i.e. cost/1.15

Is there a way to restrict the result of this calculation to two decimal places?


You could change the column type to a NUMERIC(p, 2) where p is the precision, especially if it is money (I'm guessing from cost that it might be money).

Also making a column which is derived from another column is generally a bad idea as the two can get out of sync. Consider making a view instead.


Sounds like you need the ROUND() function.

Eg. ROUND(cost/1.15, 2)

0

精彩评论

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