fork download
  1. <?php
  2.  
  3. function reduz_numero($n) {
  4. if ($n < 0) return "-" . reduz_numero(-$n);
  5. $k = "";
  6. while (round($n) >= 1000) {
  7. $k = $k . "k";
  8. $n = $n / 1000;
  9. }
  10. return round($n) . $k;
  11. }
  12.  
  13. echo " 5->" . reduz_numero( 5) . "\n";
  14. echo " 999->" . reduz_numero( 999) . "\n";
  15. echo " 1000->" . reduz_numero( 1000) . "\n";
  16. echo " 1001->" . reduz_numero( 1001) . "\n";
  17. echo " 1499->" . reduz_numero( 1499) . "\n";
  18. echo " 1500->" . reduz_numero( 1500) . "\n";
  19. echo " 1501->" . reduz_numero( 1501) . "\n";
  20. echo " 10000->" . reduz_numero( 10000) . "\n";
  21. echo " 999499->" . reduz_numero( 999499) . "\n";
  22. echo " 999500->" . reduz_numero( 999500) . "\n";
  23. echo " 999501->" . reduz_numero( 999501) . "\n";
  24. echo "1000000000->" . reduz_numero(1000000000) . "\n";
  25. echo " -77777->" . reduz_numero( -77777) . "\n";
  26. echo " 9499999->" . reduz_numero( 9499999) . "\n";
  27. echo " 9500000->" . reduz_numero( 9500000) . "\n";
  28. ?>
Success #stdin #stdout 0.02s 24400KB
stdin
Standard input is empty
stdout
         5->5
       999->999
      1000->1k
      1001->1k
      1499->1k
      1500->2k
      1501->2k
     10000->10k
    999499->999k
    999500->1kk
    999501->1kk
1000000000->1kkk
    -77777->-78k
   9499999->9kk
   9500000->10kk