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");