Showing results for 
Search instead for 
Did you mean: 
Showing results for 
Search instead for 
Did you mean: 

operators in relations.


operators in relations.

Hi gang,

Does anyone know how to convert a real number to an integer in a relation?

Something like:


Or do I need to create a new parameter of integer type and set them equal.?



23-Emerald IV

If you set one parameter equal to another, the second will change type to match the first. If you have an integer parameter and set it equal to a real parameter, the integer parameter will change type to a real. (This is how you can change parameter types after they are created without recreating them.)

To convert a real to an integer, you will need to use either the FLOOR, CEIL, functions. If you want to choose whether to round up or down automatically, you will need to write a conditional statement to pick which one to use based on your starting value.

Tom U.

Here's an example of using floor and ceil to round off a number. You ought to be able to adapt it to your needs.

/* thickness = od - id divided by 2
/* x1= step diam before rounding
/* shift moves the decimal point the number of places you want to round to
/* Interger removes the numbers to the right of the decimal
/* rounder is just the numbers to the right of the decimal
/* the following if/else statement compares the rounder to .5
/* if the rounder is equal to or larger than .5 it rounds up. If
/* the rounder is smaller than .5 it rounds down.
If rounder<.5
/* reshift moves the decimal point back to the correct place
/* d13 = the rounded step diam minus the step clearance

David Haigh

Thanks everyone!

Here is the answer:

ceil() the smallest integer not less than the real value

floor() the largest integer not greater than the real value

And I also got a great sample to use as a template.

And I never had to open a browser and go to the forum! Love this exploder!



The simple solution is to use:
This will round x up/down according to the basic rules.


A simpler method to round to an integer is this:

Rounded_parameter = floor (parameter + 0.5)

By adding 0.5, if the value is closer to the lower integer, floor will
still round down, if it's closer to the upper integer, adding 0.5 will
bump it past the upper integer so floor will essentially round up.

Doug Schaefer
Doug Schaefer | Experienced Mechanical Design Engineer

Should have real all my mail first, Bjarne beat me to it!

Doug Schaefer
Doug Schaefer | Experienced Mechanical Design Engineer

I think you're missing the point of what I was trying to do in the relation example.

Say your math ends up with a number like this 123.15963 and you want to round off to 3 places.
123,15963 x 1000 = 123159.63
123159.63 + .5 = 123160.13
Floor of 123160.13 = 123160
123160 /1000 = 123.160

Or you could do

Floor(x+.5) isn't letting you choose how many places you want to round off to.

Or perhaps I'm missing your point?

David Haigh

Ah yes, excellent point. If all you want to do is round to the nearest
integer (which I think was the original question), the simple one line
solution works. If you need to round to a specific # of places, then
some additional trickery is required.

Doug Schaefer
Doug Schaefer | Experienced Mechanical Design Engineer

"An integer is any number which can be either positive and negative but not a fractional number. It is also a whole number. Examples are -1,256, -589, -1, 0, 1, 569, 5,236. It is always a rational number."

But the whole interchange was educational regardless of the original question ..... thanks gentlemen.


Try this:
L3 = floor(1000*L) - (floor(L)*1000)
if L3 == 0
L4 = "000"
L4 = itos(L3)
L2 = itos(floor(L)) + "." + L4 + " "
SIZE = BASIC_DIA + NO_THDS + " x " + L2

The information contained in this electronic mail transmission is intended by Weil-McLain & for the use of the named individual or entity to which it is directed and may contain information that is confidential or privileged. If you have received this electronic mail transmission in error, please notify the sender of the error by reply email so that the sender's address records can be corrected and delete it from your system without copying or forwarding it, including any reply records.
Business Continuity with Creo: Learn more about it here.