Arithmetic operations

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • firebird

    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-
  • Gunnar Hjalmarsson

    #2
    Re: Arithmetic operations

    firebird wrote:[color=blue]
    > 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 .[/color]

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

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

    Comment

    • Roel van der Steen

      #3
      Re: Arithmetic operations

      On Thu, 11 Mar 2004 at 16:18 GMT, firebird wrote:[color=blue]
      > 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-[/color]

      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

      Comment

      • Jürgen Exner

        #4
        Re: Arithmetic operations

        firebird wrote:[color=blue]
        > 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?[/color]

        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


        Comment

        Working...