I am facing a problem in formatting the decimal number, Suppose i can have two decimal number in which decimal can be before or after 18th digits, format like:
$num1 = 12345678912345678912345.52458
$num2 = 123.54893256666666
for above two number my desired out is base on condition that is
for $num1: if decimal comes after 18th digit so the decimal should be just after 18digit and after that 2 digit comes as a precision only
for $num2: if decimal comes before 18th digit so the decimal should be as it is position but the precision should be only 2 digit after decimal
desired out:
$num1 = 123456789123456789.00
$num2 = 123.54
I have tried this with number number_format()
like below:
<?php
$num1 = 12345678912345678912345.52458;
$num2 = 123.54893256666666;
$num1 = number_format($num1,2,'.',''); //it is not working
$num2 = number_format($num2,2,'.',''); //it is working
echo $num1."<br>".$num2;
output:
for $num1 = 12345678912345679593472.00 where it should comes like 123456789123456789.00
for $num1 = 123.55 that is ok
please help i am not getting how to use number_format()
for $num1