IV2010Suite
Can someone tell me how to round a number up to the nearest fractional part of inch, say 32nds or 16ths or 8ths?
I can't get it to do more than the nearest whole number.
Is this a limitation?
If so, are there add-ons or other ways to do it?
Thanks ... Chris H
Solved! Go to Solution.
Solved by cwhetten. Go to Solution.
Solved by cwhetten. Go to Solution.
It might depend on what you need the parameter for. If you just want to display it in a drawing or BOM, then you can export the parameter and change the custom property format to display in architectural to the nearest 1/4", 1/8", 1/32" etc.
If you actually need to use it for a dimension or in a formula, I might have to think about it a minute to see if it is possible.
You could do it through excel easily enough... Hmm... I'll get back to you.
-cwhetten
Ok, here's a way to do it. The attached part RoundTest1.ipt has a parameter called Length whose value is not a nice fraction of an inch. The feature uses the Length parameter rounded to the nearest 1/32". This is controlled by an equation in the feature parameter d0:
round(Length * 32 ul / 1 in) * 1 in / 32 ul
All of the funky unit stuff is necessary because the round() function expects a unitless argument and returns a unitless value, but the Length and d0 parameters are in inches.
If you want to be able to change the round-off value easily (say from 1/32" to 1/8"), you could create a parameter for this round value and use that. The attached part RoundTest2.ipt uses this scheme. The formula for d0 is much simpler, too:
round(Length / RoundValue) * RoundValue
Hope this helps.
-cwhetten
IV2010 Professional SP3
Build 551 Subscription Advantage Pack
Windows 7 Pro 64-bit
Dell T3500, Intel Xeon Duo 2.40 GHz, 6 GB RAM
NVIDIA Quadro FX 1800, 768 MB
Driver Ver: 197.85
Dual Monitors, 1280x1024
cwhetten,
Very nice! Thanks for this simple solution.
One more question:
Can you please explain to me how that 'math' works?
I believe I'm ignorant of how the IV 'round' function works, or maybe I'm just forgetting some math function, which may be why I was unable to come up with your solution in the first place.
If I can understand the HOW of what you did, it may go a long way in understanding how other things work in the parameters dialogue.
Better yet, if you can direct me to a white paper that explains the way the various functions work, that would be even better.
Thanks! ... Chris
Your welcome.
The math works like this. If you want a number that is rounded to the nearest 1/32" then you are looking for a fraction that is a whole number divided by 32, like 121/32 or 8/32 or whatever. If you multiply the number by 32, then you are finding the top part of that fraction, like 121 or 8.
Now, chances are your number isn't a nice multiple of 1/32, like 3.77. When you multiply 3.77 by 32, you get 120.64, which isn't a whole number. Essentially, this is telling you that 3.77" is 120.64 thirty-seconds of an inch. To round your number to the nearest 1/32", you need to round 120.64 to the nearest whole number.
This is where the round() function comes into play. In this case, rounding 120.64 yields 121. So 3.77" rounded to the nearest 1/32" is equal to 121 thirty-seconds of an inch.
At this point, you must divide 121 by 32 to get the decimal value of your rounded number. 121/32 is equal to 3.78125, or 3 and 25/32. Therefore, 3.77" rounded to the nearest 1/32" is 3 25/32".
As for how the round() function works, the closest thing I have to any kind of official info on functions in Inventor is in the help documentation. Look in the help contents under Autodesk Inventor > Design Optimization > Parameters in Models > Quick Reference Tab > Use formulas and equations > Functions. This info isn't very specific about the functions, but from what I have gathered through experience, the floor() function rounds a number DOWN to the nearest whole number, the ceil() function rounds UP to the nearest whole number, and round() simply rounds to the nearest whole number.
For instance:
floor(3.77) = 3 floor(3.3) = 3
ceil(3.77) = 4 ceil(3.3) = 4
round(3.77) = 4 round(3.3) = 3
I hope this helps.
-cwhetten
Makes sense.
Thanks for the simple explanation.
I must admit, that sounds like some simple math manipulation that I may have known back in my h.s. days.
But these days ... "if you dont' use it, you lose it."
Thanks again! ... Chris
I am having problems getting the accepted solution to this inquiry to work... when I attempt (Round(.280 * 16 ul / 1 in) * 1 in / 16 ul) I expect the solution to come back as 5/16" rounded up. It does not. It comes back as .25 whis is obviously less then the original .280 and not rounded UP. I need to take a pipe schedule decimal and round it UP to 16ths, then add to it. Can anyone assist? Thanks in advance
Read cwhetton's second post where he shows the use of round, ceil and floor functions. Round rounds to nearest, ceil rounds up, floor rounds down. You want the ceil function instead of the round function.
Sam B
Inventor 2012 Certified Professional
Inventor Professional 2015 SP1
Windows 7 Enterprise 64-bit, SP1
HP EliteBook 8770w; 8 GB RAM; Core™ i7-3720QM 2.60 GHz; Quadro K4000M
The OP asked to Round Up and thats exactly what i need
Round.Ceil rounds to the next higher integer not decimal so it wont work for fractions of an inch.
Has anyone figuer it out?
quick question, how can i round of the number down wards? i only work with metric so this story above does not make sense ad all to me.
the answer of my formula is 3.4 so i want to keep 3 whole united which i want to use in my pattern.
i managed to find something on the great web, but inventor is screwing me over.
first of al measure fuction does not update/work properly but that besides.
if i use my calculator 3069/900 = 3.41
when i use the floor function it should be 3.
answer given by inventor = 30 😞
en this is before adding floor
answer = 3.41
i have to have this since measure function wont update but that's oke if it works.
now i have made a parameter that is always going to be 900mm coming from a part in my assembly.
next i did:
pijpstukmaatgroot/pijpstuklengte
pijpstukmaatgroot = 3069
pijpstuk lengte is 900
= 3.41 not 34. for god sake.
its 3.41 and i want to use floor in front of it to end up with the number 3.
Sorry I can't read your Russian Parameters.
To accomplish what you want, you specify the UNITS to round.
That's the key.
Example:
floor (d0 * 10 ul / 1 mm) * 1 mm / 10 ul
Notes:
- 'd0' is the parameter you want to round
- floor rounds down, ceil rounds up, round goes to closest up/down.
- 10 is 1 place to right of decimal, 100 is 2 places, etc.
Here's a link where I got that.
Sergio uses the same 'math' that I use.
I learned this many years ago from a math guy in this forum.
Too bad I forget his name, so can't give him credit!
Like my father used to say: "Give credit where credit is due!"
And he wasn't talking about greedy financiers, evil bankers or the mafia!
Adding to what @cadman777 wrote:
When equations appear in red in your parameters dialog, it means they're not valid, so you can't trust the results. They usually are invalid because of units problems but might also be due to mismatched parentheses, or function names or variables that don't exist. In this case it is because floor (and ceil and round) is a unitless function. You have to remove the linear unit (mm) from the function argument and then add it back after the function, as @cadman777 showed you in his post.
Sam B
Inventor Pro 2022.2.2 | Windows 10 Home 21H2
Dutch.
I should'a looked closer.
Had a few occasions to translate Dutch drawings in the distant past...the hard way!
One more thing: had I read this thread from the beginning, I would'a seen that this is the thread that I was talking about where @cwhetten explains the math behind rounding. THIS is that thread...duh!