Hello friends today I m going to write this tutorial about how to show only one decimal place for a number in PHP. In this tutorial we will use some random number and than we will try to show the 1 digit after the decimal. We also including the round-off for the number which will show you the difference. Lets start
// We will use any number and assign it to $number echo "Number is - ".$number= "20.587689 <br/><br/>"; //It will print - Number is - 20.587689 $number = substr($number,0,strpos($number,".") + 2); echo "Decimal strict to 1 digit - ".$number."</br>"; //It will print - Decimal strict to 2 digit - 20.58 $round="20.587689"; $round= round($round); echo "Round of number is - ".$round; //It will print - Round-off number is - 21
So here you will see that we are using a number and we can get the result of our choice. We can round it of or we can just remove the extra numbers. Thank you today we have gone through a very short but useful tutorial regarding show only one decimal place for a number in PHP.
No Comments