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

Mysql学习mysql中格式化数字详解,第1张

概述介绍《Mysql学习mysql中格式化数字详解》开发教程,希望对您有用。

《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,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,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','??'); -> 'h' MysqL>SELECT LPAD(12,0)  ->'00012'

参考:http://www.cnblogs.com/fenglIE/articles/4409208.HTMLMysqL教程

总结MysqL教程

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

总结

以上是内存溢出为你收集整理的Mysql学习mysql中格式化数字详解全部内容,希望文章能够帮你解决Mysql学习mysql中格式化数字详解所遇到的程序开发问题。

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

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1162250.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-01
下一篇 2022-06-01

发表评论

登录后才能评论

评论列表(0条)

保存