in reply to How to extract the first elemnet from an integer type value ???
my $num = 100; print "First digit of $num is " . int($num / (10 ** int(log(abs($num)) +/log(10)))) . "\n";
Make sure that some code is wrapped about it to make sure that you don't try to take log(0). log(10) is there because log is actually loge, and log10 is needed.
emc
Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.
|
|---|