Created
August 11, 2013 09:43
-
-
Save picasso250/6204191 to your computer and use it in GitHub Desktop.
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 | |
// convert with float | |
function my_base_convert($n, $from_base, $to_base) | |
{ | |
// when int | |
if (intval($n) == floatval($n)) { | |
$n = intval($n); | |
return base_convert($n, $from_base, $to_base); | |
} | |
// when float | |
$int = intval($n); | |
$int = base_convert($int, $from_base, $to_base); | |
$float = get_after_dot_from_float($n); | |
$float_to = '.'; | |
$i = 0; | |
while ($i < 100) { | |
$a = $float * $to_base; | |
$float_to .= intval($a); | |
$float = get_after_dot_from_float($a); | |
$i++; | |
} | |
return rtrim($int . $float_to, '0'); | |
} | |
function get_after_dot_from_float($float) | |
{ | |
$int = intval($float); | |
return $float = floatval($float) - $int; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment