Not seeing a Scroll to Top Button? Go to our FAQ page for more info. [PHP] Membuat Fungsi Angka Desimal | -

My Imaginations

-
Follow Me

[PHP] Membuat Fungsi Angka Desimal



By  Galeh Fatma Eko Ardiansa     April 21, 2020     

Hallo, kali ini saya akan membagikan sebuah kode PHP berupa fungsi yang digunakan untuk membuat format angka desimal sesuai dengan format yang digunakan sehari - hari (Region Indonesia) pastinya.

Berikut fungsinya

public function getNumberFloat($val,$count = 2,$usage='id')
 {
  if($val == null || $val == '')
   return 0;
  $locale=($usage == 'id')?'id_ID':'en_EN';
  if ($usage == 'en') {
   if(strstr($val,',')){
    $val=str_replace(',','.',$val);
   }
  }
  $fmt = new NumberFormatter($locale, NumberFormatter::DECIMAL);
  $fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, 0);
  $fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $count);
  $val=$fmt->format((float)$val);
        return $val;
 }

Selamat mencoba

About Galeh Fatma Eko Ardiansa

If you can dream it, you can do it | Genius is one percent inspiration and ninety-nine percent perspiration | If you don’t make mistakes, you’re not working on hard enough problems | The best and most beautiful things in the world cannot be seen or even touched - they must be felt with the heart | I can't change the direction of the wind, but I can adjust my sails to always reach my destination.

Tidak ada komentar:

Posting Komentar


Formulir Kontak

Nama

Email *

Pesan *

Advertisement

Disqus Shortname