CREATE TABLE Money (MoneyValue CURR, RoundGoal CURR)
INSERT INTO Money VALUES (1.24, 1.0)
INSERT INTO Money VALUES (1.25, 1.5)
INSERT INTO Money VALUES (1.26, 1.5)
INSERT INTO Money VALUES (1.49, 1.5)
INSERT INTO Money VALUES (1.51, 1.5)
INSERT INTO Money VALUES (1.74, 1.5)
INSERT INTO Money VALUES (1.75, 1.5)
INSERT INTO Money VALUES (1.76, 2.0)
SELECT MoneyValue, +
(INT(MoneyValue) + +
IFLT((MoneyValue - INT(MoneyValue)), .25, 0, +
IFGT((MoneyValue - INT(MoneyValue)), .75, 1, 0.5))), +
RoundGoal +
FROM Money
Dennis McGrath
Software Developer
QMI Security Solutions
1661 Glenlake Ave
Itasca IL 60143
630-980-8461
[email protected]
________________________________________
From: [email protected] [mailto:[email protected]] On Behalf Of Bill Downall
Sent: Tuesday, August 30, 2011 7:37 AM
To: RBASE-L Mailing List
Subject: [RBASE-L] - Re: Rounding
Addendum:
The simplified expression removes the division, because 2 * .50 is one, and
anything divided by one is itself:
(.50 * (int( 2 * (MoneyValue + .25))))
Bill
On Tue, Aug 30, 2011 at 8:31 AM, Bill Downall <[email protected]>
wrote:
Oops. The QA department here is going to get fired. There are 2 50 centses in
a dollar, so to use INT, I need to multiple halves into wholes, and then divide
by 2 again.
(Also had a parenthesis missing in the previous try.)
You can simplify the math below, but this seems to work, and shows all the
numbers in my twisted logic.
create table Money (moneyValue CURR, roundGoal CURR)
insert into money values (1.24, 1.0)
insert into money values (1.26, 1.5)
insert into money values (1.49, 1.5)
insert into money values (1.51, 1.5)
insert into money values (1.74, 1.5)
insert into money values (1.76, 2.0)
SELECT MoneyValue, +
(.50 * (int(( 2 * (MoneyValue + .25))) / (2 * .50) )) as RoundExpression, +
RoundGoal +
FROM Money
MoneyValue RoundExpression RoundGoal
--------------- --------------- ---------------
$1.24 1. $1.00
$1.26 1. $1.50
$1.49 1.5 $1.50
$1.51 1.5 $1.50
$1.74 1.5 $1.50
$1.76 2.0 $2.00
Bill
On Tue, Aug 30, 2011 at 8:10 AM, William Stacy <[email protected]>
wrote:
Something still wrong there, Bill. plug in 8.55 and you get 8.00.
I think Albert's approach is right and was working on a single rather colmplex
expression to do the same thing, but then I thought to myself, "Self, why are
you doing this?" I mean why would anyone want to purposely detune data like
that? Computers and R:base inherently are accurate to a penny withhout any
effort on our part... Plus rounding can introduce a compounding of errors in
certain cases. Envision a carpenter trading in his 1/16 inch graduated tape
for one with 1/2 inch graduations.
On Tue, Aug 30, 2011 at 3:44 AM, Bill Downall <[email protected]>
wrote:
Sorry, Tom, I didn't think it through. Try this:
Add .25 to your value, then take the (truncated) integer of the result, and
divide that by .50. That gives you the number of 50-cents in your answer, so
multiply all that by .50, (or divide by 2).
(.50 * (int((currvalue + .25) / .50 ))
Bill
On Mon, Aug 29, 2011 at 7:40 PM, TOM HART <[email protected]> wrote:
Bill,
I tried 7.46 and it returned 7.4, but I want 7.5
Tom
________________________________________
From: Bill Downall <[email protected]>
To: RBASE-L Mailing List <[email protected]>
Sent: Mon, August 29, 2011 4:59:29 PM
Subject: [RBASE-L] - Re: Rounding
Tom,
Multiply by fifty, find the nearest integer, then divide by 50.
((nint((50 * currencycolumn)) / 50)
Bill
On Mon, Aug 29, 2011 at 5:17 PM, TOM HART <[email protected]> wrote:
Is there a way to round currency to the nearest .50, what I want to do is
round currency the the nearest dollar or .50
eg
$1.76 to $2.00
$1.74 to $1.50
etc
Tom Hart
--
William Stacy, O.D.
Please visit my website by clicking on :
http://www.folsomeye.net
--- RBASE-L
=======================3D=======================3
D=
TO POST A MESSAGE TO ALL MEMBERS:
Send a plain text email to [email protected]
(Don't use any of these words as your Subject:
INTRO, SUBSCRIBE, UNSUBSCRIBE, SEARCH,
REMOVE, SUSPEND, RESUME, DIGEST, RESEND, HELP)
=======================3D=======================3
D=
TO SEE MESSAGE POSTING GUIDELINES:
Send a plain text email to [email protected]
In the message SUBJECT, put just one word: INTRO
=======================3D=======================3
D=
TO UNSUBSCRIBE:
Send a plain text email to [email protected]
In the message SUBJECT, put just one word: UNSUBSCRIBE
=======================3D=======================3
D=
TO SEARCH ARCHIVES:
Send a plain text email to [email protected]
In the message SUBJECT, put just one word: SEARCH-n
(where n is the number of days). In the message body,
place any
text to search for.
=======================3D=======================3
D=