![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I've got a bunch of bond rating weights from 0 to 7 in increments of .25. My input file has decimal numbers from 0 to 7, but not in increments of .25. e.g. 1.3, 2.1, and so-forth. I need to convert those numbers to the next highest number in the .25 increment scheme. The only thing that comes to mind is a monster IIF() in the spirit of: Weight_Final_Omnibus: IIf([weight_raw_omnibus]>7,999,IIf([weight_raw_omnibus] Between 6.7500001 And 7,7,IIf([weight_raw_omnibus] Between 6.500001 And 6.75,6.75,???))) But I have a feeling that when I nest that IIF statement out to handle all 29-or-whatever ranges I'm going to provoke the dreaded "Expression too complex". But even if that does not happen, the resulting expression (which I'm plugging away on right now...) is going to be ugly - to read, to debug, and to modify. Can anybody suggest a cleaner and more scalable alternative? Maybe some SQL or VBA syntax where it rounds a value up to the next .25 increment? -- PeteCresswell |
#3
| |||
| |||
|
|
Define a function to do the rounding. '-------------------- ' Round to nearest .5 ' ' dValueToRound number to be rounded only accepts numbers > 0 ' Public Function Round5(ByVal dValueToRound As Double) As Double Dim dFraction As Double ' fractional part of dValueToRound Round5 = dValueToRound If dValueToRound <= 0 Then Exit Function End If dFraction = dValueToRound - Fix(dValueToRound) If dFraction < 0.25 Then ' Round down to 2 dec dFraction = Format(dFraction, "0.00") Else If dFraction < 0.7 Then ' Round down to .5 dFraction = 0.5 Else dFraction = 1 ' Round up to 1 End If End If Round5 = Fix(dValueToRound) + dFraction End Function "(PeteCresswell)" <x@y.Invalid> wrote in message news:999ua6ltp3a96k2jtaa5kc9oba5l9dse11 (AT) 4ax (DOT) com... I've got a bunch of bond rating weights from 0 to 7 in increments of .25. My input file has decimal numbers from 0 to 7, but not in increments of .25. e.g. 1.3, 2.1, and so-forth. I need to convert those numbers to the next highest number in the .25 increment scheme. The only thing that comes to mind is a monster IIF() in the spirit of: Weight_Final_Omnibus: IIf([weight_raw_omnibus]>7,999,IIf([weight_raw_omnibus] Between 6.7500001 And 7,7,IIf([weight_raw_omnibus] Between 6.500001 And 6.75,6.75,???))) But I have a feeling that when I nest that IIF statement out to handle all 29-or-whatever ranges I'm going to provoke the dreaded "Expression too complex". But even if that does not happen, the resulting expression (which I'm plugging away on right now...) is going to be ugly - to read, to debug, and to modify. Can anybody suggest a cleaner and more scalable alternative? Maybe some SQL or VBA syntax where it rounds a value up to the next .25 increment? -- PeteCresswell |
#4
| |||
| |||
|
|
a function to do the rounding. |
#5
| |||
| |||
|
|
I'm going to go that route until somebody comes up with some SQL syntax. |
#6
| |||
| |||
|
|
Per paii, Ron: a function to do the rounding. Thanks. I'm going to go that route until somebody comes up with some SQL syntax. Create a work table. Iterate through it.... Or maybe even try embedding the call do Round5 into a query. |
#7
| |||
| |||
|
#8
| |||
| |||
|
|
Pardon me, but here is a simple expression that should work for you. -Int(-[weight_raw_omnibus] * 4)/4 John Spencer Access MVP 2002-2005, 2007-2010 The Hilltop Institute University of Maryland Baltimore County |
#9
| |||
| |||
|
|
Pardon me, but here is a simple expression that should work for you. -Int(-[weight_raw_omnibus] * 4)/4 |
![]() |
| Thread Tools | |
| Display Modes | |
| |