Mixed use of To_char and round in PostgreSQL

Source: Internet
Author: User
Tags postgresql

In PostgreSQL everyone has used round bar, how to show when the decimal point? See Example

SELECT To_char (Round (127 * 0.1/67543,6) *10000, ' 90.99 ')

1.88

SELECT To_char (Round (127 * 0.1/67543,6) *10000, ' 90.00 ')

1.88

SELECT To_char (Round (150 * 0.1/50000,6) *1000, ' 90.09 ')

0.30

SELECT To_char (Round (150 * 0.1/50000,6) *1000, ' 00.09 ')

00.30

SELECT To_char (Round (150 * 0.1/50000,6) *1000, ' 99.09 ')

.30

Did you see the rules? Hehe, the results of the above SQL show: 0 is any placeholder, if there is data on 0 bits to display the data, if there is no data on the display 0;9 is a real placeholder, 9 bits of data (greater than 0), display data, no data and nothing is displayed.

So when we want to take a percentage or thousands of points, to meet the xx.xx format, we need to use 90.99 when the placeholder

Mixed use of To_char and round in PostgreSQL

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.