470,644 Members | 1,204 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,644 developers. It's quick & easy.

Arithmetic operations

I am trying to execute the following Arithmetic operation
$perdiff = ($diff/$initval) *100.0;
This gives me a wrong value of $perdiff. For example, if,
$diff = 0.000
$initval = 0.010
Then perl returns $perdiff = 1.3 .
Any ideas why this inconsistency?

-fb-
Jul 19 '05 #1
3 3639
firebird wrote:
I am trying to execute the following Arithmetic operation
$perdiff = ($diff/$initval) *100.0;
This gives me a wrong value of $perdiff. For example, if,
$diff = 0.000
$initval = 0.010
Then perl returns $perdiff = 1.3 .


Please post the complete program that made you believe it does.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Jul 19 '05 #2
On Thu, 11 Mar 2004 at 16:18 GMT, firebird wrote:
I am trying to execute the following Arithmetic operation
$perdiff = ($diff/$initval) *100.0;
This gives me a wrong value of $perdiff. For example, if,
$diff = 0.000
$initval = 0.010
Then perl returns $perdiff = 1.3 .
Any ideas why this inconsistency?

-fb-


Really!? Are you sure!? I'm glad my system is not affected!

#/usr/bin/perl
use strict;
use warnings;

my $diff = 0.000;
my $initval = 0.010;
my $perdiff = ($diff/$initval) * 100.0;
print $perdiff;

# luckily prints 0 at my system.

PS: You are encouraged to use comp.lang.perl.misc instead of
this defunct group
Jul 19 '05 #3
firebird wrote:
I am trying to execute the following Arithmetic operation
$perdiff = ($diff/$initval) *100.0;
This gives me a wrong value of $perdiff. For example, if,
$diff = 0.000
$initval = 0.010
Then perl returns $perdiff = 1.3 .
Any ideas why this inconsistency?


I cannot reproduce your problem:
C:\tmp>type t.pl
use strict;
use warnings;
my $diff = 0.000;
my $initval = 0.010;
my $perdiff = ($diff/$initval) *100.0;
print $perdiff;

C:\tmp>t
0
C:\tmp>

jue
Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Sam Fisher | last post: by
1 post views Thread by mmacrobert | last post: by
10 posts views Thread by Massimiliano Alberti | last post: by
3 posts views Thread by Madan | last post: by
1 post views Thread by Satpreet | last post: by
8 posts views Thread by Robin Becker | last post: by
27 posts views Thread by jacob navia | last post: by
1 post views Thread by ben kipkorir | last post: by
1 post views Thread by Korara | last post: by
reply views Thread by warner | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.