Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
Three PHP programming questions?
In PHP is there a way to reduce a decimal fracture to its integer value?
Example: Convert 86,965 (86.965 in the US) to 96.
In PHP is there a way to round off a decimal fracture to its closest integer?
Example: Convert 86,965 (86.965 in the US) to 87, but 86,945 (86.465 in the US) to 86?
My PHP writes decimals the US way, using a dot (".") e.g. 0.65.
How can I change that to the European style, using a comma (","): 0,65?
1 Answer
- Anonymous1 decade agoFavorite Answer
1. use either the round (http://php.net/round), ceil (http://php.net/ceil), or floor (http://php.net/floor) functions
2. Once again, round (http://php.net/round)
3. One way I can think of (not very elegant)...
$float = 10.20;
if(strpos($float, '.')){
$float = explode('.', $float);
$float = implode(',', $float);
}
A another way:
$float = str_replace('.', ',', $float);
I am also fairly certain there is a PHP function you can use to specify what decimal separator you want to use.
ANNOTATION:
Just remembered, check out this PHP function: http://php.net/number_format and look at the first (and only) example.