MySQL handles money after the decimal point 0 extra

Source: Internet
Author: User

The cause of the problem: we are doing fund projects to generate a lot of money on the home page display home information requirements to remove the extra 0 because we in the database design when the query return data such as 18.100000 this form and we need to remove the extra 0 form of presentation 18.1

Solution:

At first I saw that using the cast () function and the CONVERT () function is the real implementation of these two functions

How to use the error:

Using select CAST (90.090008700 as decimal) can also remove the 0 execution result after the decimal point to 90.09 after 0.000008700 is removed and the usage in this way is rounded

And in the data we're querying back, we don't know exactly what to do if we don't impose a mandatory number of digits. Specify decimal (parameter 1, parameter 2) the number of bits of the parameter two decimal places so this is not enough to solve this problem.

The right way to solve the problem:

Select 0+cast (90.09008700 as char) output 90.090087

Or

Select 0+convert (' 90.09008700 ', CHAR) output results: 90.090087

In both ways, you can get the data I want at the same time when we use the query sometimes in order to avoid the return of the data is null we can use Ifnull (parameter 1, parameter 2) parameter 1 value parameter 2 when the parameter is empty can specify what we want to return the value is more than I we commonly ifnull (c ount,0) This use method if count is empty returns 0

MySQL handles money after the decimal point 0 extra

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.