PLEASE TRY THIS OUT !!! 
Author Message
 PLEASE TRY THIS OUT !!!

Quote:

> % test.pl
> Please enter no. of clients desired: 2
> --------------------Commision number 1
> Nombre: Mick Stephens
> Qtty: 1500
> Comission at 0.25 rate equals 375
> --------------------Commision number 2
> Nombre: Larry Wall
> Qtty: 7117.3
> Comission at 0.25 rate equals 1779.325

> Last Name               First Name      Comission
> ======================= =============== ==========
> Stephens                Mick                375.00
> Wall                    Larry              1779.33
>                         =============== ==========
>                         TOTAL COMMS.:      2154.32
> %

Your format line rounds the numbers, all right. 1779.325 becomes 1779.33.
But internally it is still 1779.325; Or so you would like to believe.
The time you add those numbers up, you're still adding 1779.325 + blabla.
That wouldn't account for what you're experiencing, but you should also know
that computers are notoriously inaccurate.
My guess is, that after the addition the total is something like 2154.324999999
, which is then rounded to
2154.32. What can you do?

 $tot += ($com *= 0.25);

I am not that much of a computer scientist, but apart from increasing the
bytesize of your variables,
you could change that expression to add up the $coms, and divide it by 4 at the
end. That probably decreases the introduction of errors by reducing the amount
of multiplications you do.

HTH!
--
____________________________________________________________
Frank Quednau              
http://www.*-*-*.com/ ~me51fq
________________________________________________



Fri, 22 Dec 2000 03:00:00 GMT  
 PLEASE TRY THIS OUT !!!


: Subject: Re: PLEASE TRY THIS OUT !!!

You should refrain from shouting at us.

Most folks do not like to be yelled at...

:   This message is in MIME format.  The first part should be readable text,
                    ^^^^^^^^^^^^^^

Please don't do that anymore.

Post plain text like everyone else does.

: I was beginning to learn Perl 5, so please don't flame
: me about this <maybe> stupid newbie question!

We don't generally flame for stupid newbie questions
(or we shouldn't, anyway).

We do, however, flame for re-asking of Frequently Asked Questions
that have been asked, answered, and validated hundreds (thousands?)
of times before.

Being a newbie does not exempt you from the socially acceptable
requirement of check the FAQ for a newsgroup before posting to
that newsgroup.

I hope that was a gentle flame  ;-)

I really hope that you will try to be a better Usenet citizen in the future.

: I encourage you to try this script "test.pl" out -if you're on an

Don't need to.

(and most folks will skip the rest of your article when
they see that they have to unpack it just to skim your code,
which should be plain text, and therefore does not need any sort
of "packing"...)

Have seen this question so many times before that I know what your
problem is already.

It is the very first Question in the FAQ titled "Data Manipulation"
(perlfaq4).

Shame on you for asking it yet again.

If, after seeing your FAQ above, you still don't understand why you
are getting results that you weren't expecting, please post a
question here pointing out what part you need more help with.

: I can't figure out WHY THIS TOTAL COMMS.: doesn't seem to do arithmetic
: the right way!!!! I have examined the code carefully and don't know
: what's the problem.

The problem is not in the code.

It is not even a Perl problem.

It is usual consequence of how numbers are stored in computers.

: Could you Perl gurus please help me?

I don't think it requires a guru to simply read the FAQs...

--
    Tad McClellan                          SGML Consulting

    Fort Worth, Texas



Fri, 22 Dec 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Time outs and exit codes

2. Sockets, Time-outs, and Alarms

3. trying it again... please help ;-(

4. try out my program please...

5. trying to upload file with perl CGI - help please

6. help please, trying to sort a multidimensional array

7. Please help - trying to get an Apache script to work on IIS

8. Error when trying to use dbmopen - Please help

9. Final version of Trace.pm, please try it ...

10. Trying to install on Win 98 ... Please help

11. Please, PLEASE, Help!! (probably simple)

12. Basic PERL Question - PLEASE PLEASE HELP

 

 
Powered by phpBB® Forum Software