From b378359f5f4fbfad3475f362699e3d353c1f7e80 Mon Sep 17 00:00:00 2001 From: "Bradley M. Kuhn" Date: Wed, 20 Feb 2013 07:47:33 -0500 Subject: Use a Math::BigFloat() rather than a regular float for Adjustment comparison. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Based on patch review by Loïc Dachary , we discovered that this script inconsistently used 0.02 as a float when comparing against numbers from the Math::BigFloat() package. While there were no known bugs related to this (presumably the 0.02 got coerced into a BigFloat (or vice-versa) and compared properly), this change nevertheless normalizes to use of a BigFloat for comparison. --- contrib/non-profit-audit-reports/summary-reports.plx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'contrib') diff --git a/contrib/non-profit-audit-reports/summary-reports.plx b/contrib/non-profit-audit-reports/summary-reports.plx index 78848dc5..f710d765 100755 --- a/contrib/non-profit-audit-reports/summary-reports.plx +++ b/contrib/non-profit-audit-reports/summary-reports.plx @@ -80,6 +80,7 @@ sub ParseNumber($) { Math::BigFloat->precision(-2); my $ZERO = Math::BigFloat->new("0.00"); my $ONE_PENNY = Math::BigFloat->new("0.01"); +my $TWO_CENTS = Math::BigFloat->new("0.02"); if (@ARGV < 2) { print STDERR "usage: $0 \n"; @@ -249,7 +250,7 @@ foreach my $type (keys %incomeGroups) { my($account, $amount) = ($1, $2); $amount = ParseNumber($amount); $account =~ s/\s+$//; - next if $account =~ /\/ and (abs($amount) <= 0.02); + next if $account =~ /\/ and (abs($amount) <= $TWO_CENTS); die "Weird account found, $account with amount of $amount in income command\n" unless $account =~ /^\s*Income:/; @@ -321,7 +322,7 @@ foreach my $line () { my($account, $amount) = ($1, $2); $amount = ParseNumber($amount); $account =~ s/\s+$//; - next if $account =~ /\/ and (abs($amount) <= 0.02); + next if $account =~ /\/ and (abs($amount) <= $TWO_CENTS); die "Weird account found, $account, with amount of $amount in expenses command\n" unless $account =~ /^\s*Expenses:/; @@ -416,7 +417,7 @@ foreach my $id (keys %commands) { my($account, $amount) = ($1, $2); $amount = ParseNumber($amount); $account =~ s/\s+$//; - next if $account =~ /\/ and (abs($amount) <= 0.02); + next if $account =~ /\/ and (abs($amount) <= $TWO_CENTS); next if $account =~ /^Equity:/; # Stupid auto-account made by ledger. $trialBalanceData{$id}{$account} = $amount; $fullAccountList{$account} = $id; -- cgit v1.2.3