in reply to Scientific Notation Throws Off Results.
part (which computes a number and then calculates the length of its stringified form). Perl by default uses something like $str = sprintf("%.15g",$num) to stringify floating point numbers (where the %g format chooses whether to look like %e or %f). You can do it manually instead, never using the scientfic notation, with:$answer = $pcr * $cell_size * 8; $len1 = length($answer);
You might be better off checking for numberic ranges; for instance (untested):$answer = sprintf "%.0f", $answer; $len1 = length($answer);
or a version that incorporates rounding instead of truncation:if ($answer >= 1000 && $answer < 1000000) { $answer = int($answer/1000) . " Kb/s"; } else ...
if ($answer >= 999.5 && $answer < 999500) { $answer = int($answer/1000 + .5) . " Kb/s"; } else ...
|
|---|