Detailed description of formatting numbers in mysql and detailed description of formatting in mysql

Source: Internet
Author: User

Detailed description of formatting numbers in mysql and detailed description of formatting in mysql

Recently, due to work requirements, you need to format the numbers in mysql. However, if you find that there is less information on the Internet, simply summarize it so that you can help friends who need it, let's take a look at the details below:

I. format functions:

Format floating point numberformat(number, length);

Introduction: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 shoshould be a constant value.

Sample Code

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'

2. Given digits of rpad and lpad, insufficient to add custom characters

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.

Sample Code

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.

Sample Code

mysql> SELECT LPAD('hi',4,'??'); -> '??hi' mysql> SELECT LPAD('hi',1,'??'); -> 'h' mysql>SELECT LPAD(12, 5 , 0)  ->'00012'

Reference: http://www.cnblogs.com/fenglie/articles/4409208.html

Summary

The above is all the content of this article. I hope the content of this article will help you in your study or work. If you have any questions, please leave a message, thank you for your support.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.