SQL adds thousands of bits to numbers (that is, the format of money)

Source: Internet
Author: User

It feels like a lot of stuff in the project, before the front page is to use the regular to deal with, and now because it is data query, so directly in the detection of data when it is converted to the designated thousand-bit format, the provincial front-end processing, do not speak the principle, because I also do not understand, but will use on the line, found on the Internet, and now record, Easy to see for yourself.

SQL gets the thousand bits of a number, that is, a number is three bits separated by commas, the SQL code is as follows:

 (1) Without decimal points:

Select Reverse (stuff(reverse(varchar,convert(Money,  1234333000),1)),1,3,"))

  This is a number without a decimal point, if the decimal point is imposed, the result of select is no decimal point, the result is: 1,234,333,000

  (2) with decimal points:

Select Convert (varchar,cast(121565610000.012as Money),1)

This is a number with a decimal point, only two digits after the decimal point, if the number itself does not have a decimal place, will default to two 0, because of the last argument with convert (the value here is 1).

When the value is 1, it will be two decimal places, such as 123,000.00; When the value is 2, it will be 4 digits, such as 123,000.0000; When 0, the number will be output directly (that is, there is no comma separated, but there will be two decimal places, even if the original data has no decimal places), such as: 1230000.00.

SQL adds thousands of bits to numbers (that is, the format of money)

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.