ivanichi 0 Light Poster

we can actually use number_format, but I want results that are not rounded, so I use function.

i want to change

a. 1000 >> Rp 1.000,-
b. 10000 >> Rp 10.000,-
c. 100000 >> Rp 100.000,-
d. 240857.5 >> Rp. 240.857,5

and then i create function for it, a, b and c it's ok. but
after the execution looks like this for d, Rp 24.085.7.5,- i want Rp. 240.857,5

someone please help me for check this function

<?php
 function rupiah($data)
 {
$rupiah = "";
$jml = strlen($data);

 while($jml > 3)
 {
$rupiah = "." . substr($data,-3) . $rupiah;
$l = strlen($data) - 3;
$data = substr($data,0,$l);
$jml = strlen($data);
 }
 $rupiah = "Rp " . $data . $rupiah . ",-";
 return $rupiah;
 }
 
echo rupiah (1000) ."<br>";
 echo rupiah (10000) ."<br>";
 echo rupiah (100000)."<br>";
echo rupiah (240857.5);
 ?>