Simple Convert Number & Format Currency

Cara membuat angka menjadi format uang :

function amountToStr($amount) {
    return ($amount == "-") ? $amount : number_format($amount, 0, ".", ",");
}

echo amountToStr(100000);
//result : 100,000

Cara membuat format uang menjadi angka :

function strToAmount($amount) {
    $money = "";
    $uang = explode(',', $amount);
    for ($i = 0; $i < count($uang); $i++) {
        $money .= $uang[$i];
    }
    return $money;
}
echo strToAmount('100,000'); 
//result : 100000

 

Share This Post: