到小数点后2位

时间:2014-04-14 13:47:34

标签: mysql decimal truncate

我在这里有这行查询

if (type = 1,

(IF(ISNULL(users), 
'', 
((SUM(actual) / 1) * 0.04/12) * if(users = "user", booked/(36/12),'')
))

,
'false')

示例输出为123.3333333

我希望它只输出2位小数,这样它就像123.33我应该在哪里放置Truncate或Round命令?

谢谢!

2 个答案:

答案 0 :(得分:2)

怎么样:

if (type = 1,
(IF(ISNULL(users), '', ROUND(((SUM(actual) / 1) * 0.04/12) * if(users_0.user_name = "user", booked/(36/12),''),2)))
, 'false')

答案 1 :(得分:1)

您可以使用truncate()

TRUNCATE(123.3333333, 2) = 123.33


if (type = 1,
(
  IF(ISNULL(users), '', 
  TRUNCATE(
  (
    (SUM(actual) / 1) * 0.04/12) * if(users_0.user_name = "user", booked/(36/12),'')
  ),2)

)

,
'false')