Created
February 9, 2019 00:24
-
-
Save artlung/144fe7f0c71936fe22c08eded85dacdc to your computer and use it in GitHub Desktop.
Stars try. Might suck.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getStars($number) { | |
$digits = floor($number); | |
$remainder = $number - $digits; | |
// http://php.net/round | |
$remainder = round($remainder, 0, PHP_ROUND_HALF_UP); | |
return str_repeat('*', $digits) . (($remainder > 0) ? '½' : ''); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/// maybe this is bad. | |
require 'getstars.php'; | |
for ($i=0; $i<=50;$i++) { | |
$number = $i / 10; | |
echo sprintf("%4s", $number) . " => " . getStars($number) . "\n"; | |
} | |
// 0 => | |
// 0.1 => | |
// 0.2 => | |
// 0.3 => | |
// 0.4 => | |
// 0.5 => ½ | |
// 0.6 => ½ | |
// 0.7 => ½ | |
// 0.8 => ½ | |
// 0.9 => ½ | |
// 1 => * | |
// 1.1 => * | |
// 1.2 => * | |
// 1.3 => * | |
// 1.4 => * | |
// 1.5 => *½ | |
// 1.6 => *½ | |
// 1.7 => *½ | |
// 1.8 => *½ | |
// 1.9 => *½ | |
// 2 => ** | |
// 2.1 => ** | |
// 2.2 => ** | |
// 2.3 => ** | |
// 2.4 => ** | |
// 2.5 => **½ | |
// 2.6 => **½ | |
// 2.7 => **½ | |
// 2.8 => **½ | |
// 2.9 => **½ | |
// 3 => *** | |
// 3.1 => *** | |
// 3.2 => *** | |
// 3.3 => *** | |
// 3.4 => *** | |
// 3.5 => ***½ | |
// 3.6 => ***½ | |
// 3.7 => ***½ | |
// 3.8 => ***½ | |
// 3.9 => ***½ | |
// 4 => **** | |
// 4.1 => **** | |
// 4.2 => **** | |
// 4.3 => **** | |
// 4.4 => **** | |
// 4.5 => ****½ | |
// 4.6 => ****½ | |
// 4.7 => ****½ | |
// 4.8 => ****½ | |
// 4.9 => ****½ | |
// 5 => ***** |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment