lil_v has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have a number in scientific notation and i want to transform it into a decimal number. I used sprintf for it but %f character length is limited to 6 digits after decimal. However if i specify the number of digits i need, the number is user generated so i would end up with trailing zeroes. Any suggestions? Here is my code:
my $number = $base * (10**$power); $p = sprintf("%u", $power); $number = sprintf("%.20f", $number);
Instead of ".20", I would like to use the unsigned value of $power, I dont know how to go about it...

Replies are listed 'Best First'.
Re: help with sprintf
by FunkyMonk (Bishop) on Jun 26, 2008 at 18:06 UTC
    What about...
    my $number = $base * (10**$power); $hto_visk0 = sprintf("%.${power}f", $hto_visk0);


    Unless I state otherwise, all my code runs with strict and warnings
      I tried that before and it doesnt seem to work... hence the confusion...:(
        Can you give some examples of the output you expect to see from a range of different inputs?

        Unless I state otherwise, all my code runs with strict and warnings