more useful options | |
PerlMonks |
Re: Printing with a Specific Scientific Notation Exponentby broomduster (Priest) |
on Sep 18, 2008 at 18:47 UTC ( [id://712363]=note: print w/replies, xml ) | Need Help?? |
The right way to do this, of course, is in a subroutine, where you pass in your number along with the desired fixed exponent ('-4' in your example). In that case you need to change the '4' to a variable in the $new_exp calculation. You may also want to use sprintf to format the mantissa for your output (maybe you want 500.0 instead of just 500, for example). Updated: You really need $new_exp = $exponent - $fixed_exponent; if you want to allow for an arbitrary fixed exponent. My example above applies only to negative values of the fixed exponent. Never mind. I see now at the end of the OP that ysth supplied a better answer. :-)
In Section
Seekers of Perl Wisdom
|
|