Function not working for prefix with 8[any numbers].
input: 970 output:$9.70
input: 870 output:$870
input: 800 output:$800
function toMoney( $val, $symbol = '$', $r = 2 ) {
$n = $val;
$c = is_float($n) ? 1 : number_format( $n , $r );
$d = '.';
$t = ',';
$sign = ( $n < 0 ) ? '-' : '';
$i = $n = number_format( abs( $n ), $r );
$j = ( ( $j = $i.length ) > 3 ) ? $j % 3 : 0;
return $symbol.$sign .( $j ? substr( $i, 0, $j) + $t : '').preg_replace('/(\d{3})(?=\d)/',"$1" + $t,substr($i,$j)) ;
}
Function taken from: Money conversion not worked
The above error rectified in the below
function toMoney( $val, $symbol = '$', $r = 2 ) {
$n = $val;
$c = is_float($n) ? 1 : number_format( $n , $r );
$d = '.';
$t = ',';
$sign = ( $n < 0 ) ? '-' : '';
$i = $n = number_format( abs( $n ), $r );
$j = ( ( $j = strlen($i) ) > 3 ) ? $j % 3 : 0;
return $symbol.$sign .( $j ? substr( $i, 0, $j) + $t : '').preg_replace('/(\d{3})(?=\d)/',"$1" + $t,substr($i,$j)) ;
}