PHP code to make Indonesia Rupiah Format
Simple Indonesia Rupiah Format in PHP. Here The Code:
function rupiah($a){
if(stripos($a, ".")===FALSE){$a = $a.".00";}
$pecah = explode(".", $a);
$depan = strrev($pecah[0]);
$belakang = $pecah[1];
$jum = strlen($depan);
$res = "";
for($i=0;$i<=$jum-1;$i++){
if($i%3==0 and $i!=0){$res.=".".$depan[$i];}
else{$res.=$depan[$i];}
}
return "Rp ".strrev($res).",".$belakang;
}
$a = "2090705.57";
echo rupiah($a);
if(stripos($a, ".")===FALSE){$a = $a.".00";}
$pecah = explode(".", $a);
$depan = strrev($pecah[0]);
$belakang = $pecah[1];
$jum = strlen($depan);
$res = "";
for($i=0;$i<=$jum-1;$i++){
if($i%3==0 and $i!=0){$res.=".".$depan[$i];}
else{$res.=$depan[$i];}
}
return "Rp ".strrev($res).",".$belakang;
}
$a = "2090705.57";
echo rupiah($a);
Good Luck !!!
0 comments:
Post a Comment