Advertisement
martinms

Helper.php

May 19th, 2024
489
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.61 KB | None | 0 0
  1. <?php
  2.  
  3. function formatNumber($number, $maxFraction = 2)
  4. {
  5.     if ($number == 0 || $number == null)
  6.         return;
  7.  
  8.     $formatted = number_format($number, $maxFraction, ',', '.');
  9.  
  10.     // get fraction part
  11.     $fraction = explode(',', $formatted)[1];
  12.  
  13.     // if fraction part is 0, remove it
  14.     if ($fraction == '00')
  15.         return number_format($number, 0, ',', '.');
  16.  
  17.     return $formatted;
  18. }
  19.  
  20. function formatRupiah($str)
  21. {
  22.     return number_format($str, 0, ',', '.');
  23. }
  24.  
  25. function percentage($number, $total)
  26. {
  27.     if ($total == 0)
  28.         return 0;
  29.  
  30.     return ($number / $total) * 100;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement