i'm new to php. please i would want to get figure from user's input amount such as if a user pays 2500 i want to get 2.5 from the amount he inputed examples below
1000 ------ 1 ,
1500 ------ 1.5,
1600 ------ 1.6 ,
1800 ------ 1.8 ,
2000 ------ 2 ,
2200 ------ 2.2 ,
2500 ------ 2.5 ,
etc
is there any way i can get something like this above or to divide user input amount to get something like the figures above please
$num = 1700;
$whole = (int) $num;
$frac = $num / $whole;
Divide it by 1000, round down to 1 digit after decimal point and round down to prevent 7.95 becoming 8.
<?php
$num = 7950;
echo round($num / 1000, 1, PHP_ROUND_HALF_DOWN); // 7.9