Does any one know how can I format the number and limited it to only show 1 decimal place in php?
Example:
How can I format the number 2.10 to 2.1 in php?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use PHP’s
number_formathttp://php.net/manual/en/function.number-format.php
Example:
$one_decimal_place = number_format(2.10, 1);If you ever need to convert it back to a float:
$the_float_value = floatval($one_decimal_place);Also, this article is a good reference for different decimal characters and separator styles.