Extjs4-PHP retains two decimal float formats

Source: Internet
Author: User
Now there is a need to extract a large batch of five decimal digits from the database, and then retain two decimal places. After using round, I simply processed it and found that numbers such as 19.90000 would change to 19.9 instead of 19.90. So I tried to format it with numberformat, and changed it to 19.90 without asking... now I have a requirement to retrieve a large batch of five decimal digits from the database, and then keep two decimal places. After using round, I simply processed it and found that numbers such as 19.90000 would change to 19.9 instead of 19.90. So I tried to format it with number format and changed it to 19.90. But it still needs to be displayed on the front-end in the gridpanel of extjs. By default, the grid supports sorting. I ordered it and found that the numbers are sorted by the first letter, that is:
18.88
19.12
2.27
2.50
21.00
21.33
The number is sorted by the first letter in the string format.
My problem is: How can I use PHP to handle it? It can retain two decimal places and convert it to a number format. To be honest, I'm not sure whether PHP can support such a format, so if you can implement some Extjs configurations, thank you very much!

Reply content:

Now there is a need to extract a large batch of five decimal digits from the database, and then retain two decimal places. After using round, I simply processed it and found that numbers such as 19.90000 would change to 19.9 instead of 19.90. So I tried to format it with number format and changed it to 19.90. But it still needs to be displayed on the front-end in the gridpanel of extjs. By default, the grid supports sorting. I ordered it and found that the numbers are sorted by the first letter, that is:
18.88
19.12
2.27
2.50
21.00
21.33
The number is sorted by the first letter in the string format.
My problem is: How can I use PHP to handle it? It can retain two decimal places and convert it to a number format. To be honest, I'm not sure whether PHP can support such a format, so if you can implement some Extjs configurations, thank you very much!

string number_format ( float $number [, int $decimals = 0 ] )
The returned value of number_format in php is string.
2 solutions
1. Return the number directly to the front-end. The front-end is formatted as two decimal places.
2. php format, but the original value is also returned to the front end for sorting

Phpround()Function

Echo sprintf ("% 0.2f", "19.90000 ");

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.