Contact: aviboots(AT)netvision.net.il
43,874 questions
57,260 answers
573 users
function first_decimal_digit(float $f): int { $s = sprintf("%.4f", $f); // format to 4 decimals return (int)$s[strrpos($s, ".") + 1]; } $f = 23.5876; echo first_decimal_digit($f); /* run: 5 */
function first_decimal_digit(float $f): int { return (int)(floor(abs($f) * 10)) % 10; } $f = 23.6876; echo first_decimal_digit($f); /* run: 6 */