Convert ToMoney function not working
<p>Function not working for prefix with 8[any numbers].</p>

<p>input: 970 output:$9.70<br>
input: 870 output:$870<br>
input: 800 output:$800</p>

<pre><code>function toMoney( $val, $symbol = '$', $r = 2 ) {
    $n = $val; 
    $c = is_float($n) ? 1 : number_format( $n , $r );
    $d = '.';
    $t = ',';
    $sign = ( $n &lt; 0 ) ? '-' : '';
    $i = $n = number_format( abs( $n ), $r ); 
    $j = ( ( $j = $i.length ) &gt; 3 ) ? $j % 3 : 0; 

   return  $symbol.$sign .( $j ? substr( $i, 0, $j) + $t : '').preg_replace('/(\d{3})(?=\d)/',"$1" + $t,substr($i,$j)) ;
}
</code></pre>

<p>Function took from below thread</p>

<p><a href="http://stackoverflow.com/questions/6369887/how-we-can-use-money-format-function-in-php-on-windows-platform">Money conversion not worked</a></p>

<p>The above error rectified in the below </p>

<pre><code>  function toMoney( $val, $symbol = '$', $r = 2 ) {
        $n = $val; 
        $c = is_float($n) ? 1 : number_format( $n , $r );
        $d = '.';
        $t = ',';
        $sign = ( $n &lt; 0 ) ? '-' : '';
        $i = $n = number_format( abs( $n ), $r ); 
        $j = ( ( $j = strlen($i) ) &gt; 3 ) ? $j % 3 : 0; 

       return  $symbol.$sign .( $j ? substr( $i, 0, $j) + $t : '').preg_replace('/(\d{3})(?=\d)/',"$1" + $t,substr($i,$j)) ;
    }
</code></pre>
