当前位置:首页 > IT技术 > 数据库 > 正文

mysql数学函数之truncate用法
2021-10-11 15:04:30

语法
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

本文摘自 :https://blog.51cto.com/u