Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function formatNumber($number, $maxFraction = 2)
- {
- if ($number == 0 || $number == null)
- return;
- $formatted = number_format($number, $maxFraction, ',', '.');
- // get fraction part
- $fraction = explode(',', $formatted)[1];
- // if fraction part is 0, remove it
- if ($fraction == '00')
- return number_format($number, 0, ',', '.');
- return $formatted;
- }
- function formatRupiah($str)
- {
- return number_format($str, 0, ',', '.');
- }
- function percentage($number, $total)
- {
- if ($total == 0)
- return 0;
- return ($number / $total) * 100;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement