最近因为工作的需求,需要对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:

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

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'

总结

更多相关文章

  1. MySQL系列多表连接查询92及99语法示例详解教程
  2. Android(安卓)- Manifest 文件 详解
  3. Android的Handler机制详解3_Looper.looper()不会卡死主线程
  4. Android(安卓)EditView
  5. Selector、shape详解(一)
  6. android2.2资源文件详解4--menu文件夹下的菜单定义
  7. Android发送短信方法实例详解
  8. Android(安卓)读取资源文件实例详解
  9. 详解Android中的屏幕方向

随机推荐

  1. [Android] TroubleShooting: Android req
  2. 重写EditText回车键跳到下一个EditText
  3. Android开发札记初级(三)探索Android(安卓)
  4. Android 各个版本号WebView
  5. android:adjustViewBounds 、android:cro
  6. Android的AlertDialog详解
  7. Android输入框自动提示
  8. Compile android NDK without Eclipse
  9. android activity设置全屏以及Android获
  10. Android系统启动之Zygote