Turn on suggestions

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

Showing results for

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

ziedhosni

Active Participant

10-28-2016 03:02 PM

Options

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Hello,

I would like to round numbers following a grid.

Let's say I have a grid of 6 between 3 and 4 ( 3.0 3.2 3.4 3.6 3.8 4.0)

I would like to round to the nearest number of the grid, so if I choose 3.7125, it will be round to 3.8.

I found already in the forum how to round to certain degree of decimal but not in my approach.

Do you know to force the rounding to the nearest of the grid.

I was thinking of a ramp up to make the grid then interpolate the number and use its index to round. But I am sure there is a much easier way.

Thanks,

Zied

Solved! Go to Solution.

10-28-2016 03:10 PM - edited 10-28-2016 03:10 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

billko

Proven Zealot

10-28-2016 03:10 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

@ziedhosni wrote:Hello,

I would like to round numbers following a grid.

Let's say I have a grid of 6 between 3 and 4 ( 3.0 3.2 3.4 3.6 3.8 4.0)

I would like to round to the nearest number of the grid, so if I choose 3.7125, it will be round to 3.8.

I found already in the forum how to round to certain degree of decimal but not in my approach.

Do you know to force the rounding to the nearest of the grid.

I was thinking of a ramp up to make the grid then interpolate the number and use its index to round. But I am sure there is a much easier way.

Thanks,

Zied

Not exactly sure what you mean, but does "Interpolate 1 D Array" do it for you?

Bill

(Mid-Level minion.)

My support system ensures that I don't look totally incompetent.

Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.

Humble author of the CLAD Nugget.

(Mid-Level minion.)

My support system ensures that I don't look totally incompetent.

Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.

Humble author of the CLAD Nugget.

billko

Proven Zealot

10-28-2016 03:13 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Oops I see what you are trying to do. I like your approach, but let's see what the heavy hitters here think of it. They often have better solutions because they are the gurus.

Bill

(Mid-Level minion.)

My support system ensures that I don't look totally incompetent.

Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.

Humble author of the CLAD Nugget.

(Mid-Level minion.)

My support system ensures that I don't look totally incompetent.

Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.

Humble author of the CLAD Nugget.

ben64

Trusted Enthusiast

10-28-2016 03:22 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Here's a possibility.

Ben64

--------------------------------------------------

The best way to say thanks is to give kudos!

The best way to say thanks is to give kudos!

Kyle97330

Active Participant

10-28-2016 03:42 PM - edited 10-28-2016 03:44 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Here's a version that doesn't use arrays, so it theoretically scales to infinity without an increase in memory space or processing time.

(The "False" case just wires the coerce output straight through)

However it doesn't work with grids that don't have even steps between the numbers, and I don't know if that's a possibility.

Solution

Accepted by topic author ziedhosni

RavensFan

Knight of NI

10-28-2016 03:44 PM - edited 10-28-2016 03:49 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Those ideas all seem to work if you are trying to round to a set of specific values. But you need to define the specifc values for all possibilities.

If you want to round to a specific interval, there is an easier way to do it.

So you want to round to each 0.2. Divide your number by that interval. Round to the nearest integer. Multiply your number by that interval.

If you need to force a number that is lower or higher than a given range to be within that range, such as having 1.255 round UP to 3, then put an In Range and Coerce either before or after this bit of code.

Bob_Schor

Knight of NI

10-28-2016 03:49 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

@ziedhosni wrote:Hello,

I would like to round numbers following a grid.

Let's say I have a grid of 6 between 3 and 4 ( 3.0 3.2 3.4 3.6 3.8 4.0)

I would like to round to the nearest number of the grid, so if I choose 3.7125, it will be round to 3.8.

Zied,

Usually when one talks about "rounding", they aren't talking about numbers restricted to a range, say between 3 and 4. As an example, what would you want 1.55 to round to, 3.0 or 1.6?

If you want to "round to the nearest 0.2" (and, perhaps, later deal with the question of restricting numbers between 3 and 4), you can "play mathematician" and solve your problem: divide by the interval 0.2 (making them range from 15 to 20), round to the nearest integer, then multiply by the interval (bringing them back to the range 3 .. 4). As long as you have an evenly spaced grid that lands on an integer, you can use this trick.

Bob Schor

10-28-2016 05:02 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Thank you guys. Unfortunately, I cannot choose all the solutions . I picked up one.

I hope I can get as many feedback for another post I put 2 weeks ago and it is not solved yet .

Cheers,

Zied

GregSands

Active Participant

10-30-2016 03:25 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator