topic How to round a number to a specific value and not to a number of decimals in LabVIEW
https://forums.ni.com/t5/LabVIEW/How-to-round-a-number-to-a-specific-value-and-not-to-a-number-of/m-p/3363242#M989725
<P>Hello,</P><P>I would like to round numbers following a grid.</P><P>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)</P><P>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.</P><P>I found already in the forum how to round to certain degree of decimal but not in my approach.</P><P>Do you know to force the rounding to the nearest of the grid.</P><P>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.</P><P>Thanks,</P><P>Zied</P>Fri, 28 Oct 2016 20:02:04 GMTziedhosni2016-10-28T20:02:04ZHow to round a number to a specific value and not to a number of decimals
https://forums.ni.com/t5/LabVIEW/How-to-round-a-number-to-a-specific-value-and-not-to-a-number-of/m-p/3363242#M989725
<P>Hello,</P><P>I would like to round numbers following a grid.</P><P>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)</P><P>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.</P><P>I found already in the forum how to round to certain degree of decimal but not in my approach.</P><P>Do you know to force the rounding to the nearest of the grid.</P><P>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.</P><P>Thanks,</P><P>Zied</P>Fri, 28 Oct 2016 20:02:04 GMThttps://forums.ni.com/t5/LabVIEW/How-to-round-a-number-to-a-specific-value-and-not-to-a-number-of/m-p/3363242#M989725ziedhosni2016-10-28T20:02:04ZRe: How to round a number to a specific value and not to a number of decimals
https://forums.ni.com/t5/LabVIEW/How-to-round-a-number-to-a-specific-value-and-not-to-a-number-of/m-p/3363247#M989728
<P>I did the following but I am not sure if it can be easier as I feel it is ressources consuming as the speed does matter.</P>Fri, 28 Oct 2016 20:10:48 GMThttps://forums.ni.com/t5/LabVIEW/How-to-round-a-number-to-a-specific-value-and-not-to-a-number-of/m-p/3363247#M989728ziedhosni2016-10-28T20:10:48ZRe: How to round a number to a specific value and not to a number of decimals
https://forums.ni.com/t5/LabVIEW/How-to-round-a-number-to-a-specific-value-and-not-to-a-number-of/m-p/3363248#M989729
<BLOCKQUOTE><HR /><LI-USER uid="249458"></LI-USER> wrote:<BR /><P>Hello,</P><P>I would like to round numbers following a grid.</P><P>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)</P><P>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.</P><P>I found already in the forum how to round to certain degree of decimal but not in my approach.</P><P>Do you know to force the rounding to the nearest of the grid.</P><P>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.</P><P>Thanks,</P><P>Zied</P><HR /></BLOCKQUOTE><P>Not exactly sure what you mean, but does "Interpolate 1 D Array" do it for you?</P>Fri, 28 Oct 2016 20:10:57 GMThttps://forums.ni.com/t5/LabVIEW/How-to-round-a-number-to-a-specific-value-and-not-to-a-number-of/m-p/3363248#M989729billko2016-10-28T20:10:57ZRe: How to round a number to a specific value and not to a number of decimals
https://forums.ni.com/t5/LabVIEW/How-to-round-a-number-to-a-specific-value-and-not-to-a-number-of/m-p/3363249#M989730
<P>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.</P>Fri, 28 Oct 2016 20:13:41 GMThttps://forums.ni.com/t5/LabVIEW/How-to-round-a-number-to-a-specific-value-and-not-to-a-number-of/m-p/3363249#M989730billko2016-10-28T20:13:41ZRe: How to round a number to a specific value and not to a number of decimals
https://forums.ni.com/t5/LabVIEW/How-to-round-a-number-to-a-specific-value-and-not-to-a-number-of/m-p/3363252#M989732
<P>Here's a possibility.</P><P> </P><P><IMG src="https://forums.ni.com/t5/image/serverpage/image-id/190689i779F9315803708DC/image-size/original?v=v2&px=-1" border="0" alt="nrearest value.png" title="nrearest value.png" /></P><P> </P><P>Ben64</P>Fri, 28 Oct 2016 20:22:15 GMThttps://forums.ni.com/t5/LabVIEW/How-to-round-a-number-to-a-specific-value-and-not-to-a-number-of/m-p/3363252#M989732ben642016-10-28T20:22:15ZRe: How to round a number to a specific value and not to a number of decimals
https://forums.ni.com/t5/LabVIEW/How-to-round-a-number-to-a-specific-value-and-not-to-a-number-of/m-p/3363261#M989735
<P>Here's a version that doesn't use arrays, so it theoretically scales to infinity without an increase in memory space or processing time.</P><P><IMG src="https://forums.ni.com/t5/image/serverpage/image-id/190690iB2A0C5CF1E5B820B/image-size/original?v=v2&px=-1" border="0" alt="Round to grid.png" title="Round to grid.png" /></P><P>(The "False" case just wires the coerce output straight through)</P><P> 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.</P>Fri, 28 Oct 2016 20:44:47 GMThttps://forums.ni.com/t5/LabVIEW/How-to-round-a-number-to-a-specific-value-and-not-to-a-number-of/m-p/3363261#M989735Kyle973302016-10-28T20:44:47ZRe: How to round a number to a specific value and not to a number of decimals
https://forums.ni.com/t5/LabVIEW/How-to-round-a-number-to-a-specific-value-and-not-to-a-number-of/m-p/3363262#M989736
<P>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.</P><P> </P><P>If you want to round to a specific interval, there is an easier way to do it.</P><P>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. </P><P> <IMG src="https://forums.ni.com/ni/attachments/ni/170/989736/1/Example_VI.png" border="0" alt="" title="" /></P><P> </P><P> </P><P>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.</P>Fri, 28 Oct 2016 20:49:17 GMThttps://forums.ni.com/t5/LabVIEW/How-to-round-a-number-to-a-specific-value-and-not-to-a-number-of/m-p/3363262#M989736RavensFan2016-10-28T20:49:17ZRe: How to round a number to a specific value and not to a number of decimals
https://forums.ni.com/t5/LabVIEW/How-to-round-a-number-to-a-specific-value-and-not-to-a-number-of/m-p/3363266#M989740
<BLOCKQUOTE><HR /><LI-USER uid="249458"></LI-USER> wrote:<BR /><P>Hello,</P><P>I would like to round numbers following a grid.</P><P>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)</P><P>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.</P><P> </P><P> </P><HR /></BLOCKQUOTE><P>Zied,</P><P> 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?</P><P> 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.</P><P> </P><P>Bob Schor</P>Fri, 28 Oct 2016 20:49:43 GMThttps://forums.ni.com/t5/LabVIEW/How-to-round-a-number-to-a-specific-value-and-not-to-a-number-of/m-p/3363266#M989740Bob_Schor2016-10-28T20:49:43ZRe: How to round a number to a specific value and not to a number of decimals
https://forums.ni.com/t5/LabVIEW/How-to-round-a-number-to-a-specific-value-and-not-to-a-number-of/m-p/3363291#M989756
<P>Thank you guys. Unfortunately, I cannot choose all the solutions . I picked up one.</P><P>I hope I can get as many feedback for another post I put 2 weeks ago and it is not solved yet .</P><P><img id="heart" class="emoticon emoticon-heart" src="https://forums.ni.com/i/smilies/16x16_heart.gif" alt="Heart" title="Heart" /></P><P>Cheers,</P><P>Zied</P>Fri, 28 Oct 2016 22:02:44 GMThttps://forums.ni.com/t5/LabVIEW/How-to-round-a-number-to-a-specific-value-and-not-to-a-number-of/m-p/3363291#M989756ziedhosni2016-10-28T22:02:44ZRe: How to round a number to a specific value and not to a number of decimals
https://forums.ni.com/t5/LabVIEW/How-to-round-a-number-to-a-specific-value-and-not-to-a-number-of/m-p/3363453#M989827
<P>This is what the Threshold 1D Array function does - as long as your array of numbers is in ascending order.</P>Sun, 30 Oct 2016 20:25:45 GMThttps://forums.ni.com/t5/LabVIEW/How-to-round-a-number-to-a-specific-value-and-not-to-a-number-of/m-p/3363453#M989827GregSands2016-10-30T20:25:45Z