MySQL中數學函數之truncate用法

語法

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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章