0
点赞
收藏
分享

微信扫一扫

MySQL中数学函数之truncate用法

大漠雪关山月 2022-06-28 阅读 31

语法

TRUNCATE(X,D)

Returns the number X, truncated to D decimal places. If D is 0, the result has no decimal point or fractional part. D can be negative to cause D digits left of the decimal point of the value X to become zero.
返回数字X,截断到D小数位。 如果D为0,结果没有小数点或小数部分。 D是负数,导致值X的小数点左边的D数字变为零。

实例:

SELECT truncate(1314.1314, 3);          # 1314.131
SELECT truncate(1314.1314, 1); # 1314.1
SELECT truncate(1314.1314, 0); # 1314
SELECT truncate(1314.1314, -1); # 1310
SELECT truncate(1314.1314, -3); # 1000
SELECT truncate(-1314.1314, -1); # -1310
SELECT truncate(-1314.1314, -3); # -1000
SELECT truncate(1314.1314*100, -3); # 131000


举报

相关推荐

0 条评论