Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

** Community Tip** - New to the community? Learn how to post a question and get help from PTC and industry experts!
X

- Community
- Creo (Previous to May 2018)
- Creo Modeling Questions
- operators in relations.

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Mar 22, 2012
04:47 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Mar 22, 2012
04:47 PM

operators in relations.

Hi gang,

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

Something like:

"SEGMENT_QTY=(INPUT_RADIUS*2*PI)INT"

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

Thanks

-Nate

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

Something like:

"SEGMENT_QTY=(INPUT_RADIUS*2*PI)INT"

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

Thanks

-Nate

10 REPLIES 10

Mar 22, 2012
05:31 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Mar 22, 2012
05:31 PM

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.

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.

Mar 22, 2012
05:55 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Mar 22, 2012
05:55 PM

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

thickness=(d15-d14)/2

/* x1= step diam before rounding

x1=d14+thickness

/* shift moves the decimal point the number of places you want to round to

shift=x1*1000

/* Interger removes the numbers to the right of the decimal

Interger=floor(shift)

/* rounder is just the numbers to the right of the decimal

rounder=shift-interger

/* 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

rounded=floor(shift)

else

rounded=ceil(shift)

endif

/* reshift moves the decimal point back to the correct place

reshift=rounded/1000

/* d13 = the rounded step diam minus the step clearance

d13=reshift-0.05

David Haigh

/* thickness = od - id divided by 2

thickness=(d15-d14)/2

/* x1= step diam before rounding

x1=d14+thickness

/* shift moves the decimal point the number of places you want to round to

shift=x1*1000

/* Interger removes the numbers to the right of the decimal

Interger=floor(shift)

/* rounder is just the numbers to the right of the decimal

rounder=shift-interger

/* 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

rounded=floor(shift)

else

rounded=ceil(shift)

endif

/* reshift moves the decimal point back to the correct place

reshift=rounded/1000

/* d13 = the rounded step diam minus the step clearance

d13=reshift-0.05

David Haigh

Mar 22, 2012
10:35 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Mar 22, 2012
10:35 PM

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!

-Nate

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!

-Nate

Mar 23, 2012
03:25 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Mar 23, 2012
03:25 AM

The simple solution is to use:

floor(x+.5).

This will round x up/down according to the basic rules.

/Bjarne

floor(x+.5).

This will round x up/down according to the basic rules.

/Bjarne

Mar 23, 2012
09:00 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Mar 23, 2012
09:00 AM

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

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

Mar 23, 2012
09:02 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Mar 23, 2012
09:02 AM

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

Doug Schaefer

Doug Schaefer

Mar 23, 2012
10:51 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Mar 23, 2012
10:51 AM

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

Shift=(x1*1000)+.5

Rounded=floor(shift)/1000

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

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

Shift=(x1*1000)+.5

Rounded=floor(shift)/1000

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

Mar 23, 2012
11:04 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Mar 23, 2012
11:04 AM

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

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

Mar 23, 2012
11:12 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Mar 23, 2012
11:12 AM

"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.

Don

Mar 23, 2012
11:23 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Mar 23, 2012
11:23 AM

Try this:

L3 = floor(1000*L) - (floor(L)*1000)

if L3 == 0

L4 = "000"

else

L4 = itos(L3)

endif

L2 = itos(floor(L)) + "." + L4 + " "

SIZE = BASIC_DIA + NO_THDS + " x " + L2

[cid:image001.jpg@01CD08DE.56D51720]

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.

L3 = floor(1000*L) - (floor(L)*1000)

if L3 == 0

L4 = "000"

else

L4 = itos(L3)

endif

L2 = itos(floor(L)) + "." + L4 + " "

SIZE = BASIC_DIA + NO_THDS + " x " + L2

[cid:image001.jpg@01CD08DE.56D51720]

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.