I have been banging my head against the wall and thought i should find some help. This is some really basic addition and subtraction that should equal 0.

`#!/usr/bin/perl
use strict;
my $first_num = '-3500.78';
my $second_num = '-1057.12';
my $third_num = '5100';
my $fourth_num = '-681';
my $fifth_num = '46.3';
my $sixth_num = '46.3';
my $seventh_num = '46.3';
print "FIRST NUMBER = $first_num\n";
print "SECOND NUMBER = $second_num\n";
print "THIRD NUMBER = $third_num\n";
print "FOURTH NUMBER = $fourth_num\n";
print "FIFTH NUMBER = $fifth_num\n";
print "SIXTH NUMBER = $sixth_num\n";
print "SEVENTH NUMBER = $seventh_num\n";
my $total = $first_num + $second_num + $third_num + $fourth_num + $fif
+th_num + $sixth_num + $seventh_num;
print "TOTAL = $total\n\n";
#BREAK IT DOWN
my $first_total = $first_num + $second_num;
print "#1: $first_num + $second_num = $first_total\n";
my $second_total = $first_total + $third_num;
print "#2: $first_total + $third_num = $second_total\n";
my $third_total = $second_total + $fourth_num;
print "#3: $second_total + $fourth_num = $third_total\n";
my $fourth_total = $third_total + $fifth_num;
print "#4: $third_total + $fifth_num = $fourth_total\n";
my $fifth_total = $fourth_total + $sixth_num;
print "#5: $fourth_total - $sixth_num = $fifth_total\n";
my $sixth_total = $fifth_total + $seventh_num;
print "#6: $fifth_total + $seventh_num = $sixth_total\n";
`

Here are the results of the program:

FIRST NUMBER = -3500.78

SECOND NUMBER = -1057.12

THIRD NUMBER = 5100

FOURTH NUMBER = -681

FIFTH NUMBER = 46.3

SIXTH NUMBER = 46.3

SEVENTH NUMBER = 46.3

TOTAL = 3.5527136788005e-13

#1: -3500.78 + -1057.12 = -4557.9 (correct)

#2: -4557.9 + 5100 = 542.1 (correct)

#3: 542.1 + -681 = -138.9 (correct)

#4: -138.9 + 46.3 = -92.5999999999996 (WHAT?)

#5: -92.5999999999996 - 46.3 = -46.2999999999996 (WHAT?)

#6: -46.2999999999996 + 46.3 = 3.5527136788005e-13 (WHAT?)

I have a program that goes out and adds a budget up and kept encountering this problem. I decided to simplify it and break it down to try to find where the issue is. Been a long day and think my brains are just leaking out of my head.
Thanks in advance,
-vptimmy

Comment onSimple addition/subtraction not workingDownloadCode