国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > MySQL > 正文

mysql中格式化數字詳解

2024-07-24 13:13:55
字體:
來源:轉載
供稿:網友

最近因為工作的需求,需要對mysql/251418.html">mysql中數字進行格式化,但發現網上的資料較少,索性自己總結一下,方便自己也幫助有需要的朋友們,下面話不多說,來一起看看詳細的介紹:

一、format函數:

格式化浮點數 format(number, length);

介紹: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> 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 給定位數,不足補充自定義字符

RPAD:

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> SELECT RPAD('hi',5,'?');   -> 'hi???' mysql> SELECT RPAD('hi',1,'?');   -> 'h'mysql>SELET RPAD(12, 5 ,0);  ->12000

This function is multi-byte safe.

LPAD:

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> 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.html

總結

以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對VeVb武林網的支持。


注:相關教程知識閱讀請移步到MYSQL教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 邹城市| 乌拉特后旗| 顺义区| 南城县| 桂林市| 金川县| 海伦市| 视频| 益阳市| 武乡县| 潼南县| 桦川县| 县级市| 新乡县| 会东县| 和硕县| 宾川县| 峨眉山市| 五华县| 清丰县| 会昌县| 大名县| 新闻| 泸水县| 金山区| 团风县| 苗栗县| 巨野县| 陕西省| 湟源县| 北宁市| 逊克县| 三河市| 望江县| 旅游| 龙南县| 曲靖市| 靖边县| 乌兰察布市| 文昌市| 昂仁县|