Contact: aviboots(AT)netvision.net.il
40,849 questions
53,254 answers
573 users
$f = 239.5876; $s = sprintf("%.4f", $f); echo $s[0]; /* run: 2 */
function get_first_digit($f) { $first_digit = $f; while ($first_digit >= 9) { $first_digit = (int)($first_digit / 10); } return $first_digit; } $f = 761.7261; echo get_first_digit($f); /* run: 7 */
function get_first_digit($f) { $total_digits_minus_one = (int)log10($f); $first_digit = (int)($f / pow(10, $total_digits_minus_one)); return $first_digit; } $f = 9618.7261; echo get_first_digit($f); /* run: 9 */