i want to covert this number 23333333to 23 only with php function and if it be 2 dont make 20 just make 2
You can use the number_format function in PHP to achieve this:
$num = 2.3333333; $formatted_num = number_format($num, 1);
This will result in $formatted_num being equal to "2.3".
If the number is 2, you can use an if statement to check:
$num = 2; if ($num == (int)$num) { $formatted_num = (int)$num; } else { $formatted_num = number_format($num, 1); }
This will result in $formatted_num being equal to "2".
原文地址: https://www.cveoy.top/t/topic/gyoI 著作权归作者所有。请勿转载和采集!