當(dāng)前位置:首頁 > IT技術(shù) > 數(shù)據(jù)庫 > 正文

mysql數(shù)學(xué)函數(shù)之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.?
返回數(shù)字X,截斷到D小數(shù)位。 如果D為0,結(jié)果沒有小數(shù)點或小數(shù)部分。 D是負數(shù),導(dǎo)致值X的小數(shù)點左邊的D數(shù)字變?yōu)榱恪?/br>


實例
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

開通會員,享受整站包年服務(wù)立即開通 >