extjs4-php reserved two-bit decimal float format

Source: Internet
Author: User
Now there is a need to remove a large lump of five decimal digits from the database, and then reserve two decimal places. I used the round to simply deal with it and found that numbers like 19.90000 would turn 19.9 instead of 19.90. So I tried to format it with number, and it turned out to be 19.90, but it still needs to be in the front end, shown in the ExtJS Gridpanel. The grid supports sorting by default, and I ordered it and found that the numbers were sorted alphabetically, that is:
18.88
19.12
2.27
2.50
21.00
21.33
It's equivalent to sorting numbers in the first letter of a string.
My question is: how can be handled with PHP, both two decimal places, and can be converted to digital format, I am not sure that PHP can support such a form, so if you can use some of the ExtJS configuration implementation, but also very grateful!

Reply content:

Now there is a need to remove a large lump of five decimal digits from the database, and then reserve two decimal places. I used the round to simply deal with it and found that numbers like 19.90000 would turn 19.9 instead of 19.90. So I tried to format it with number, and it turned out to be 19.90, but it still needs to be in the front end, shown in the ExtJS Gridpanel. The grid supports sorting by default, and I ordered it and found that the numbers were sorted alphabetically, that is:
18.88
19.12
2.27
2.50
21.00
21.33
It's equivalent to sorting numbers in the first letter of a string.
My question is: how can be handled with PHP, both two decimal places, and can be converted to digital format, I am not sure that PHP can support such a form, so if you can use some of the ExtJS configuration implementation, but also very grateful!

string number_format ( float $number [, int $decimals = 0 ] )
PHP Number_format returns a string.
2 Solutions
1, direct number returned to the front end, the front-end display when the format of 2 decimal places
2, PHP format, but the original value is also returned to the front-end, to sort

Functions of PHP round()

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.