Akopia Akopia Services

[Date Prev][Date Next][Thread Prev][Thread Next][Minivend by date ][Minivend by thread ]

Re: [mv] [subtotal] error



******    message to minivend-users from Mike Heins <mikeh@minivend.com>     ******

Quoting Barry Treahy, Jr. (Treahy@mmaz.com):
> >
> > Okay, I've been working with this for three days now and I'm stuck.  My
> > subtotal is mysteriously adding a penny to itself, even after I've put
> > in some truncating code:
> >
> > [discount ALL_ITEMS] ((int ($s * .7 * 100)) / 100) [/discount]
> 
> Dan, perhaps I'm missing something but I do not believe the INT function is rounding but truncating.
> Take a look:
> 
> doorstop:/#  perl -e 'print (int(100.016*100)/100);print "\n"'
> 100.01
> doorstop:/#  perl -e 'print (int(100.012*100)/100);print "\n"'
> 100.01
> doorstop:/#  perl -e 'print (int(100.018*100)/100);print "\n"'
> 100.01
> 
> What about modifying your discount to do explicit rounding:
> 
> [discount ALL_ITEMS] ((int ($s * .7 * 100+.499)) / 100) [/discount]
> 
> doorstop:/#  perl -e 'print (int(100.018*100+.499)/100);print "\n"'
> 100.02
> doorstop:/#  perl -e 'print (int(100.014*100+.499)/100);print "\n"'
> 100.01
> 

This is the classic programming language floating-point rounding
situation. See the routine Vend::Util::round_to_frac_digits to look
at how Minivend solves this anomaly in the pricing and taxing routines.

Whole businesses have been built on efficiently solving this problem
in financial transaction environments.

-- 
Akopia, Inc., 131 Willow Lane, Floor 2, Oxford, OH  45056
phone +1.513.523.8220 fax 7501 <heins@akopia.com>

Clothes make the man.  Naked people have little or no influence on
society.  -- Mark Twain
-
To unsubscribe from the list, DO NOT REPLY to this message.  Instead, send
email with 'UNSUBSCRIBE minivend-users' in the body to Majordomo@minivend.com.
Archive of past messages: http://www.minivend.com/minivend/minivend-list


Search for: Match: Format: Sort by: