SHARE
TWEET

Function Bulatkan Angka (Dinamis)

GarryLaly Mar 13th, 2014 171 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. function bulatkan_angka($ke, $num) {
  3.     $potong1 = substr($num, 0, $ke-1);
  4.     $potong2 = ceil(substr($num, $ke-1, strlen($num)));
  5.     $bulat = substr($potong2, 1, 1);
  6.     $bulat1 = substr($potong2, 0, 1);
  7.     $bulat2 = $bulat>=5?$bulat1+1:$bulat1;
  8.     $nol = "";
  9.     for ($i = 0;$i < strlen($potong2)-1;$i++) {
  10.         $nol .= "0";
  11.     }
  12.     $hasil = $potong1.$bulat2.$nol;
  13.     echo (int)$hasil;
  14. }
  15.  
  16. bulatkan_angka(4, 8161824.6);
  17. ?>
RAW Paste Data
Top