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