mysql中格式化数字详解,mysql格式化详解

发布时间:2019-05-18  栏目:LINUX  评论:0 Comments

多年来因为做事的急需,供给对mysql中数字实行格式化,但开掘互连网的材料较少,索性本身计算一下,方便本身也赞助有须要的心上大家,下边话不多说,来一齐探访详细的介绍:

mysql中格式化数字详解,mysql格式化详解

近日因为做事的必要,必要对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

总结

以上便是那篇小说的全部内容了,希望本文的故事情节对我们的学习或然办事能拉动一定的佑助,假若有问号大家能够留言沟通,多谢大家对帮客之家的支持。

http://www.bkjia.com/Mysql/1221561.htmlwww.bkjia.comtruehttp://www.bkjia.com/Mysql/1221561.htmlTechArticlemysql中格式化数字详解,mysql格式化详解
方今因为职业的须求,需求对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

总结

上述便是那篇文章的全体内容了,希望本文的内容对我们的就学或许办事能带来一定的相助,假如有疑问大家能够留言沟通,感谢我们对台本之家的支撑。

你可能感兴趣的小说:

留下评论

网站地图xml地图