《Mysql學習mysql中格式化數字詳解》要點:
本文介紹了Mysql學習mysql中格式化數字詳解,希望對您有用。如果有疑問,可以聯系我們。
最近因為工作的需求,需要對mysql中數字進行格式化,但發現網上的資料較少,索性自己總結一下,方便自己也幫助有需要的朋友們,下面話不多說,來一起看看詳細的介紹:MYSQL教程
一、format函數:
MYSQL教程
格式化浮點數 format(number, length);
MYSQL教程
介紹:Formats the number X to a format like '#,###,###.##', rounded to D decimal places, and returns the result as a string. If D is 0, the result has no decimal point or fractional part. D should be a constant value.
MYSQL教程
示例代碼MYSQL教程
mysql> SELECT FORMAT(12332.123456, 4); -> '12,332.1235' mysql> SELECT FORMAT(12332.1,4); -> '12,332.1000' mysql> SELECT FORMAT(12332.2,0); -> '12,332'
二、rpad 和 lpad 給定位數,不足補充自定義字符
MYSQL教程
RPAD:
MYSQL教程
Returns the string str,right-padded with the string padstr to a length of len characters. If
str is longer than len, the return value is shortened to len characters.??????MYSQL教程
示例代碼??MYSQL教程
mysql> SELECT RPAD('hi',5,'?'); -> 'hi???' mysql> SELECT RPAD('hi',1,'?'); -> 'h' mysql>SELET RPAD(12, 5 ,0); ->12000
This function is multi-byte safe.MYSQL教程
LPAD:MYSQL教程
Returns the string str, left-padded with the string padstr to a length of lencharacters. If str is longer than len, the return value is shortened to lencharacters.
MYSQL教程
示例代碼MYSQL教程
mysql> SELECT LPAD('hi',4,'??'); -> '??hi' mysql> SELECT LPAD('hi',1,'??'); -> 'h' mysql>SELECT LPAD(12, 5 , 0) ->'00012'
參考:http://www.cnblogs.com/fenglie/articles/4409208.htmlMYSQL教程
總結MYSQL教程
以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對維易PHP的支持.MYSQL教程
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/3644.html