Need some help with rounding to nearest thousand...

pbare

Well Known Member
I know that this shouldn't be difficult but I just can't wrap my head around it :-(

I have a field that I have calculated that needs to be rounded to the nearest thousand.

Calc Total = 232,600

Should be rounded to 233,000

I already do a ceil(Calc Total) but that just rounds to the nearest whole number. Is there a different function that I can use?
Pam
 
1)Divide by a 1000
2 Use the Round system function on the result (0 decimal places)
3)Multiply by a 1000

smile.gif
 
Just a caution, I think for that to work you would need something like...

mnNumVar = 1000*(round(mnNumVar/1000,0)

or however ER allows you to do it. The round needs to work on the interim results of the divide
 
OR you could just use Round Value N0000146 and pass in 232,600 into Value (bi-directional) and pass in 1,000 into Round Factor and you will get back 232,000 in the Value field. You can also set the break point anywhere you want. It will default at 5 (round up) if you leave it blank. It has been in the software since B7333. It can also accommodate any numbers (the largest being 29d9).

Ben again,
 
Not to pick nits, but shouldn't passing in 232,600 with a 1,000 round factor return a value of 233,000?
smile.gif
 
Hi All, I just wanted to talk to the function Round Value a little more now that I have time. This is a really cool function in that it can round by any multiple of 10 as we are all pretty well versed, but it can round by ANY number - something that is not as easy to comprehend.

Example: When you round 134.59 by 1 you get 135 - by 10 you get 130 - by .1 you get 134.60 - all pretty easy right? However you can round by 12 if you want and get 132. What is the value of that, you may ask. Before I answer, let's think of rounding a little differently.

With the example of 134.59 rounded by 10 (the Round Factor) we either get 130 (if rounded down) and 140 (if rounded up). Obviously many of you will say "NO it's 130....140 is not an option" and that is a valid response because we are all used to rounding to the closest value. We have in our minds, set the Break Point to 5 and said to ourselves that the value is closer to 130. If we had set the Break Point to 2 then we would've rounded up and the value would indeed be 140. Notice that what we have found are the two multiples of 10 (our Round Factor) that sit on either side of the Value that we are rounding. If we set the Break Point to 10 (the same value as the Round Factor then we would ALWAYS round DOWN. Conversely, If we set the Break Point to .001 then we would (almost) ALWAYS round UP. Either way, we are basically finding the MULTIPLE of the Round Factor.

"So What?" you are probably asking right now. "How does this help us?" Good questions! So I am going to now give you a couple of situations where this is applicable. I have only been thinking of this for about 30 minutes, so these are far from the only situations where you can apply this knowledge.

Situation 1: I have to build a house with 20,000 board feet of 2x4s and I have to purchase those 2x4s in length of 15 foot lengths. How many boards do I need? Well, you would just Round the 20,000 by 15 and make sure the value rounded UP (set the Break Point at .01). the result is that I need 20,010 board feet or (/15) 1,334 boards.

Situation 2: I have 130 feet of wire that I want to wrap into a motor coil or magnetic coil and the coil is .5 feet in diameter. How many full coils will I get? Well, you would just Round the 130 feet by .5x3.14159 (1.570795) (pi time diam) and make sure the value rounded DOWN (set the Break Point at 1.570795) to get the result of 128.805 feet or 82 coils.

Situation 3: I have 50,000,000 dodads (Ea) how many gross do I have? I just Round the value 50,000,000 (DOWN) by 144,000 and get...49,968,000 or 347 gross. If you don't care how many gross, just how many are used vs. left overs, you are already there!

Now I know if you've gotten this far that you are probably saying that it would not be much different to just do the math. You are probably right, but now I've gotten you to think about rounding a little differently, haven't I? Also, think about the application if you needed to round a decimal value by a hex or octal number just plug in the rounding value of 16^^x or 8^^x and you've got it.

Administrative note. Round Value works for Rounding negative or positive numbers. The Round Factor and Break Point also take negative or positive values, but the negative/positive value for Round Factor is ignored.

Yes, I'm a nerd.
Ben again,
 
Back
Top