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

Hello Monks,

The following code:

my $result = 4.25 / 1200;

Yields:

0

How do I make $result contain:

0.0035417

I tried:

$result = sprintf "0.7f", 4.25 / 1200;

That didn't work.

Replies are listed 'Best First'.
Re: Dividing and result of zero.
by ikegami (Patriarch) on Jan 05, 2009 at 00:57 UTC

    my $result = 4.25 / 1200; Yields 0

    It shouldn't, and it doesn't for me.

    >perl -le"$result = 4.25 / 1200; print $result" 0.00354166666666667

    I tried $result = sprintf "0.7f", 4.25 / 1200; That didn't work.

    $result = sprintf "%0.7f", 4.25 / 1200; ^ | missing
Re: Dividing and result of zero.
by ysth (Canon) on Jan 05, 2009 at 01:13 UTC