首页 > 数据库技术 > 详细

Mysql 对数字的格式化

时间:2017-01-04 22:51:21      阅读:193      评论:0      收藏:0      [点我收藏+]

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

Mysql 对数字的格式化

原文:http://www.cnblogs.com/duhuo/p/6250338.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!