PDA

View Full Version : Rounding Formula



krista.manna
2006-09-18, 02:35 PM
Out of curiosity (even though I'm pretty sure this is impossible) is there a way to write a formula that will round all numbers UP to the nearest whole number. INT will round down & I need all numbers to round up.


Any thoughts would be helpful.

Thanks,
-K-

greg.mcdowell
2006-09-18, 02:41 PM
something like this... (Area / Occupant Load Factor QA) / 1' ^ 2) + 0.49

david.fannon
2006-09-18, 03:44 PM
(Area / Occupant Load Factor QA) / 1' ^ 2) + 0.49

This is a good technique but is only as accurate as the 0.49, and will produce an incorrect value if your calculation is out to more decimal places. For example 10.001 will return 10, not 11. If you care about having it work for all values (and you and/or your building code may not) you could add something using an if statement:

Type: NUM
Occupant Calc = (Area/Square Feet Per Occupant)

Type: INT
Occ Calc Int = Occupant Calc
Occupant Load = if(Occupant Calc-Occ Calc Int>0, Occ Calc Int+1,Occ Calc Int)

One advantage to this process (I think) is that it more closely represents the thinking "we divide the area by the load factor, and if there is any fraction left over we go up to the next whole person"

The occupant calculation (however you set that up) will calculate out to however many decimal places it needs. The if statement in "Occupant Load" compares the occupant load with decimals to the one "rounded" using INT. If the INT is equal to the calculation, or is already rounding up, no worries. If INT is actually rounding down, the formula simply bumps it up by one. Since it uses the greater then symbol it is good for as many decimal places as Revit calculates.

dbaldacchino
2006-09-18, 05:26 PM
Nice solution, that will work in all cases.

Steve Mintz
2006-09-19, 05:46 PM
I developed some formulas to do any kind of rounding (and showed them to development in the hopes they would give us more Excel-like formulas):

Parameter Num as Number = 1.8
Parameter calc_int as Integer
Parameter calc_float as Number

To round up to the nearest whole number:
calc_int = Num + 0.4999 = 2


To round down to the nearest whole number:
calc_int = Num - 0.5000 = 1


To round nearest to the next fractional portion (i.e. to the nearest quarter)

calc_int = 4 * Num = 7
calc_float = 1/4*calc_int = 1.75 [edit]

dbaldacchino
2006-09-19, 10:09 PM
What's B? I don't see how that's working.

Steve Mintz
2006-09-20, 04:24 PM
What's B? I don't see how that's working.
Sorry! I was copying from an earlier write up I made using parameters A, B, and C. I figured it would be easier to understand if I gave them meaningful names. I have edited my original post to read correctly.

dbaldacchino
2006-09-20, 04:41 PM
Ohhhh I get it now. I like how you used the integer vs number parameters to obtain those results.