-2

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;
2
  • 3
    Not clear what you want. Divide by 1000? Commented Jun 27, 2024 at 10:40
  • i want to get a figure from user input like if a user inputs 1000 i would want to get 1, if a user inputs 3500 i want to get 3.5 or if a user inputs 7950, i would want to get 7.9 Commented Jun 27, 2024 at 10:58

1 Answer 1

0

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

https://www.php.net/manual/en/function.round.php

Sign up to request clarification or add additional context in comments.

1 Comment

perfect, exactly what am looking for.. Thank you so much bro

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.