mysql 算数格式化,Mysql学习mysql中格式化数字详解

搜索热词

《MysqL学习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,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,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','??');

-> 'h'

MysqL>SELECT LPAD(12,0)

->'00012'

参考:http://www.cnblogs.com/fenglie/articles/4409208.html

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对编程之家PHP的支持.

总结

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值