MySQL If processing currency money type

Source: Internet
Author: User

We know that the database storage money type can be float, double, decimal, compared to decimal is the best use.

Well, our company is divided into units, type with bigint access, operation of the time to is very convenient, when the show will have to turn.

The result is a bug.

Look at the problem first,

The database reads money and retains two decimal places.

    <SelectId="Findsummoney" Resulttype="Java.lang.Double">            SELECTFORMAT (Ifnull (sum( Money),0)/  -,2)         fromR_orderWHEREUID=#{uid} andState= 1         andPay_typeinch(1,2, A)        GROUP  byUID</Select>

As a result, when money is greater than 1000, it is converted into 1,000.00 by format.

The program then hits the exception. Can not be converted to this type, the original conversion method is greater than 1000, automatically add a comma to the string type, double cannot receive, because do not want to change the code,

In the end, use the CONVERT function:

    <SelectId="Findsummoney" Resulttype="Java.lang.Double">            SELECT            Convert(Ifnull (sum( Money)/ -,0),DECIMAL(9,2))         fromR_orderWHEREUID=#{uid} andState= 1         andPay_typeinch(1,2, A)        GROUP  by#{uid}</Select>

The resolution returned is 1000.00

MySQL If processing currency money type

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.