Bill,
That works and is exactly what I am looking for. Thanks
Tom Hart
________________________________
From: Bill Downall <[email protected]>
To: RBASE-L Mailing List <[email protected]>
Sent: Tue, August 30, 2011 7:36:34 AM
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
>>
>>
>>
>>
>