Click here to Skip to main content
15,893,486 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am getting the data through the api and when it comes to the price of the product data is like amount -> 18625 and fractionDigits->2. So in this case the output should be 186.25,
How can I do this with php.


What I have tried:

I have tried the number_format method but not working
Posted
Updated 18-Aug-21 1:38am
Comments
Richard MacCutchan 18-Aug-21 7:37am    
You need to divide it by 100 to get the parts either side of the decimal point.

Try PHP: number_format - Manual[^] and PHP: pow - Manual[^]
PHP
$x = 18625;
$fractionDigits = 2;
echo number_format($x / pow(10, $fractionDigits), $fractionDigits);
 
Share this answer
 
See PHP Operators[^] for how to get the quotient and remainder.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900