472,962 Members | 2,787 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,962 software developers and data experts.

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 3699
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Sam Fisher | last post by:
Hi, I have a situation where I have to support a large number(not decimals), something of the order of 20 to 30 digits in the database(sql server 2000) I am not able to use LONG data type as it...
1
by: mmacrobert | last post by:
Hi there, I'm having trouble making some code do a "graceful" recovery for mathematical operations. Certain functions e.g. log10, will call "matherr" and provides an avenue for intervention in a...
10
by: Massimiliano Alberti | last post by:
Are there rules on how should the C behave with the arithmetic operations? Are the overflows always ignored? And are they simply truncated? (if I have a 16-bits unsigned short ints unsigned short...
3
by: Madan | last post by:
Hi all, I had problem regarding float/double arithmetic only with + and - operations, which gives inaccurate precisions. I would like to know how the arithmetic operations are internally handled...
1
by: Satpreet | last post by:
I'm looking to simulate the behavior of a digital hardware arithmetic block in a C/C++ program. I was just wondering if there are any libraries (with datatypes and overloaded operators etc.)...
26
by: Bill Reid | last post by:
Bear with me, as I am not a "professional" programmer, but I was working on part of program that reads parts of four text files into a buffer which I re-allocate the size as I read each file. I...
8
by: Robin Becker | last post by:
Hi, just trying to avoid wheel reinvention. I have need of an unsigned 32 bit arithmetic type to carry out a checksum operation and wondered if anyone had already defined such a beast. Our...
27
by: jacob navia | last post by:
As Richard Bos rightly pointed out, I had left in my classification of types the C99 types Complex and boolean. Here is a new classification. Those are not mentioned in the classification of...
1
by: ben kipkorir | last post by:
In this assignment we shall look at a possible representation of rational numbers in java using objects. The java language represents rational numbers using the same representation used for other...
2
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - Why does simple decimal arithmetic give strange results?...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.