How to round a number to a specific value and not to a certain number of decimal places

Hello

I'd round up the numbers according to 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'd round up to the nearest number in the grid, so if I choose 3.7125, it will turn to 3.8.

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

You know to force rounding to the nearest of the grid.

I thought a ramp up to make the grid then interpolate the number and use its index to round. But I don't know that there is a much easier way.

Thank you

Zied

These ideas, everything seems to work if you try to round up to a set of specific values.  But you must set specific values for all the possibilities.

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

If you want to round each 0.2.  Divide your number of this interval.  Round to the nearest integer.  Multiply your number of this interval.

If you need to force a number less than or greater than a given to be in this range, such as having range 1.255 round up to 3, then put a stove and Coerce before or after this piece of code.

Tags: NI Software

Similar Questions

  • To the number of decimal places control user input

    Hey everybody,

    I am all new to LabVIEW and just learn how it works. I was wondering if there was a way to allow user input to change the number of decimal places (the output of my function is infinitely extensible).

    I tried, but it did not work:

    Using a digital input, I appended a string with "%" + '[INPUT]' + 'f' with the number of function concat strings and string functions. I used the resulting string as the formatting string in the value format function.

    This doesn't quite work. The output should be something like "28.274", but instead, it displays "283f. Anyone know why? Is there a better way to do it?

    In addition, attach a picture of the front panel and diagram of block for clarity.

    (Yes, it's homework, but the assignment does not include allowing the user to adjust the number of decimal places, it's just something I would like to add.)

    Get rid of the number 2 for the width of your decimal string number.  It requires a space before a number to a number.  %. 6F is not equal to % .6f.  The string format don't quite understand the first format string.

    (PS.  It helps if you attach your VI.  In this way we can play with what you have rather than trying to recreate it from scratch.)

  • After software update today, my password does not work.  My phone is now disabled.  I don't have a backup.  How can I start to use my phone again and not lose all my content?

    After software update today, my password does not work.  My phone is now disabled.  I don't have a backup.  How can I start to use my phone again and not lose all my content?  Help, please.

    You can not

  • How I can scan the registry valuHi, how I can scan the Windows 7 registry value and how do I come to know if the registry value is same as it has been installed previously?

    Hello

    How can I scan the Windows 7 registry value and how do I come to know if the registry value is same as it has been installed previously?

    Hello
     
    The Windows registry is a vast and vital part of the computer, which continues to evolve being modified or deleted or new entries are created all the time.
     
    Case where the registry keys of change.
     
    At startup
     
    So that updates
     
    While making customization or custom settings in windows
     
    While to install the software
    Virus... etc.
     
     
    Each click Open and save is related to the registry.
     
    This is something very tedous to verify the integrity of a registry of windows with all of the above modifications being carried out.
     
    You can back up the registry of the computer after you install Windows new and update with all Windows updates and the custom software, into a registry backup or create a system image / restore point.
     
    Please visit these links for more information.

    Windows registry Description of the audit of the Windows Registry tool (Scanreg.exe) How do I add, edit or delete subkeys in registry and values by using a registration entries (.reg) file Hope this information helps

     
     
     
  • Number of decimal places of precision for numeric fields Standard

    Is there a number of decimal places of precision integrated in PLM4P for standard, off-screen digital box? This level of precision is editable for the system, or on a case-by-case?

    Thank you

    Zach

    We don't currently support it. The default precision is 5 digits.

  • How to record a combined PDF file as binding, and not as a portfolio?

    How to record a combined PDF file as binding, and not as a portfolio?

    Hello

    If you use Acrobat

    Go to file > create > combine files into a single PDF file...

    From the windows of files combine, select the PDF files you want to combine

    Click the gear on the top icon in the Center

    Clear the Save as PDF portfolio option

    Click OK then the combine button

    Thank you

    Abhishek

  • How can I sort the selector non-unique values and make them unique in the structure of the case?

    I want to clarify 3 ranges as breeders of the case.  For example, I am able mV and I want 0.10, 10.20 and 20.30, but, when I enter them in this way, I get an error that says that the selection values are not unique.

    I want case to answer when the input is greater than 0 but less than 10.

    I want the second case to react when the input is greater than 10, but less than 20.

    I want the third case to react when the input is higher than 20, but less than 30.

    And there is the case by default, 0.  The case structure think my default is bunk with my case?  How a list correctly these ranges in the Tag Chooser structure cases to avoid the error?

    Also, I plugged in my blood "to LONG integer" and then to the Terminal case structure to convert entire for the entry of case structure (blue wire).  Is it the right thing to do, because my values of tension will certainly be decimal numbers, not integers.

    Before converting in I32, for example, use "turn to + inf" and settle the case accordingly.

    (A plain to_I32 rounds to the nearest integer, making it impossible to meet limits).

  • How do I change my lightroom ver 6.5 and not cc?

    And why adobe cannot answer this question?

    I go to my lightroom, drop the Help menu and click on update.  He wants to update lightroom cc and not 6.5!  What gives?  How can I do this?

    LR CC and LR 6 are exactly the same program, even to install files. It's how you Sign In, which makes it one or the other.

    Sign with a Adobe which is related, related to a subscription ID and it becomes LR CC.

    Sign in with an Adobe ID that is NOT associated with a subscription package, and he then asks for a serial number. After you enter a valid serial number and a series of a previous version if the LR 6 series is for the upgraded version, it becomes LR 6.

    Other than that, it is to say the current sign, they are exactly the same program, even to install files and even installed the files on your computer.

  • Change the number of decimal places according to the value of the field

    Hello world

    I'm doing a form using Adobe Acrobat.

    I want a field that usually has only 2 decimal places, to have 4 decimal positions ONLY when necessary.

    Example: If the value of the field is 3.53 that's fine, but if the value is 3,5346 I want to show him this.

    I played around field properties and I realized that I need to use a custom format script. I don't know where to start, however. Can you point me in the right direction?

    Thank you in advance.

    I just threw together quickly and did not test, take is as a general guide. It is intended to be placed in a JavaScript to the document level and called from custom Format script of the field. You can not put it simply everything as the script to Format because of the way that Acrobat behaves when you do.

    The point of the script is to calculate the number to use as the first parameter to the AFNumberFormant function, which is that Acrobat uses when configuring a digital format. I couldn't think of a clever name for the function, so I leave it to you:

    function fmt1() {
    
        // Set the minimum number of digits to the right of the decimal
        var min = 2;
    
        // Get the field value, as a string
        var val = event.value;
    
        // Round to the nearest 10-thousand of a cent
        var rn = util.printf("%.4f", val);
    
        // Replace any trailing zeroes with nothing
        rn = rn.replace(/[0]+$/, "");
    
        // Get the number of characters after the decimal
        var num = rn.split(".")[1].length;
    
        // Set to the minimum if appropriate
        if (num < 2) num = 2;
    
        // Use built-in formatting function
        AFNumber_Format(num, 2, 0, 0, "\u20ac", true);
    
    }
    

    Call it like that in the case of the field Format:

    fmt1();
    

    If this isn't a calculated field, but the one who interacts with a user, you'll want to add a function with the swing, something like:

    function keystroke1() {
    
        AFNumber_Keystroke(2, 2, 0, 0, "\u20ac", true);
    
    }
    
  • firefox 38-how can I get the box options old back and NOT a browser with the orders page?

    I want to go the pop up box that opens when I go to TOOLS - OPTIONS and NOT a web browser page. How do I do that?

    The browser.preferences.inContent is no longer supported in Firefox 42 and later is not possible to open an independent window by setting this pref to false.
    Bug 1140495 - Remove glass preferences support

    Optionally, create a button on the toolbar of bookmarks for the subject: preferences and hold the Shift key and left click to open the page in a new window.

    You can watch the extension Classic theme restaurateur.

  • How to set permissions for sharing by computer/object and not by the user, share Mac and no Windows Pc

    I wonder if anyone knows how put share permissions on an object such as a Mac in my case instead of the windows user.

    We do not have our Macs in Active Directory, we seek to share an external hard drive only Mac and not the Windows PC on the network using active directory. I tried sharing the hard drive of a PC to anyone and both PC and Mac can access to this, but we do want Macs to see and access it and not everyone. There is no selection shares with the name of the computer in the share permissions, so the only way to do is share it to everyone. The Mac, accounts are local to the Mac and the PC on Active Directory, so what I do is have a way to share this folder with only Mac and all the Windows PC. All solutions, all ideas will help.

    Thank you

    One thing I can suggest is to share the hard drive of a Mac and make sure that the hard drive is formatted in HFS file system + and not NTFS. Windows does not recognize HFS +. In this way, Windows users will not be able to access the hard disk.

    Alternative methods may be available with Mac. Please contact Apple support in this regard.

  • Number of decimal places in Write Back

    Hi all

    We use the writeback option ERPi/FDMEE to rewrite data in Oracle EBS12. Everything works correctly, but when extracting data from Hyperion FDMEE takes data in 7-8 decimal places. Is it possible for this round to 2 decimal places when exporting data?

    What version of FDMEE?

    When the data is written back to the LES, it is actually extracted using a view.

    For EBS, there is a view named AIF_EBS_GL_INTERFACE_V, where you can find the SQL code to extract data from FDMEE

    You can try to change this view to include a ROUND for the column amount:

    CREATE OR REPLACE VIEW "FDMEE" OF THE FORCE. "" AIF_EBS_GL_INTERFACE_V "("SEGMENT1","SEGMENT2","SEGMENT3", 'SEGMENT4', 'SEGMENT5', 'SEGMENT6', 'SEGMENT7', 'SEGMENT8', 'SEGMENT9', 'SEGMENT10', 'DIRECTION11', 'SEGMENT12', 'SEGMENT13', 'SEGMENT14', 'SEGMENT15', 'SEGMENT16', 'SEGMENT17', 'SEGMENT18', 'SEGMENT19', 'SEGMENT20', 'SEGMENT21', 'SEGMENT22', 'SEGMENT23', 'SEGMENT24', 'SEGMENT25', 'SEGMENT26', 'SEGMENT27', 'SEGMENT28', 'SEGMENT29', 'SEGMENT30', 'QUANTITY', 'ACCOUNTING_DATE', 'CURRENCY',"LOADID","ACCOUNT_TYPE") AS

    SELECT UD1X, UD2X, UD3X, UD4X, UD5X, UD6X, UD7X, UD8X, UD9X, UD10X, UD11X, UD12X, UD13X, UD14X, UD15X, UD16X, UD17X, UD18X, UD19X, UD20X, UD21X, UD22X, UD23X, UD24X, UD25X, UD26X, UD27X, UD28X, UD29X, UD30X, ROUND (SUM (AMOUNTX), 2), PERIODKEY, CURKEY, LOADID, ATTR1 FROM TDATASEGW WHERE VALID_FLAG = 'Y' GROUP OF UD1X, UD2X, UD3X, UD4X, UD5X, UD6X, UD7X, UD8X, UD9X, UD10X, UD11X, UD12X, UD13X, UD14X UD15X, UD16X, UD17X, UD18X, UD19X, UD20X, UD21X, UD22X, UD23X, UD24X, UD25X, UD26X, UD27X, UD28X, UD29X, UD30X, PERIODKEY, CURKEY, LOADID, ATTR1;

    I hope that helps

  • HOW IT SCALES AN IMAGE TO A SPECIFIC WIDTH AND HEIGHT?

    I need to resize an image to 851 X 315, such that recommended by Facebook to fit in the timeline, but when I type 851 in the width, the height is going to 532.

    the problem is when I change the height to 315, the length is reduced once again, this is not supposed to.

    Should I separate them and how?  And which would result in distortions? Thank you

    set the crop tool to hold at 851 x 315

    Given that your image is not proportional to this dimension, you'll trim the outside part.

  • Search for page elements in a specific layer, and not in the entire document

    Hello

    could you please help me to modify this script, then it can look only to the elements of the page ("Date", "Time", "Version", 'Code of component Ops') in a single specific layer named "Legend" instead of all the layers?

    /**********************************************************
    
    
    ADOBE SYSTEMS INCORPORATED 
    Copyright 2005-2006 Adobe Systems Incorporated 
    All Rights Reserved 
    
    
    NOTICE:  Adobe permits you to use, modify, and 
    distribute this file in accordance with the terms
    of the Adobe license agreement accompanying it.  
    If you have received this file from a source 
    other than Adobe, then your use, modification,
    or distribution of it requires the prior 
    written permission of Adobe. 
    
    
    *********************************************************/
    
    
    /** Saves every document open in Illustrator
      as a PDF file in a user specified folder.
    */
    
    
    // Main Code [Execution of script begins here]
    try {
      // uncomment to suppress Illustrator warning dialogs
      // app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
    
    
      if (app.documents.length > 0 ) 
      {
      var options, i, sourceDoc, targetFile,;
    
      // Get the PDF options to be used
      options = this.getOptions();
      if (options != null) 
      {
      sourceDoc = app.activeDocument; // returns the document object
      var fullName = sourceDoc.fullName;
      fullName = fullName.toString();
    
      var destFolder = fullName.slice(0,fullName.lastIndexOf("/"))
      var dateFound = false;
      var versionFromName = fullName.slice(fullName.lastIndexOf("-")+1, fullName.lastIndexOf("_"));
      var opsFromName = fullName.slice(fullName.lastIndexOf("/")+1, fullName.lastIndexOf("-"));
      var theVersionNumber = null;
      var dateField = null;
      var timeField = null;
      var opsVersionCode = null;
      for(i=0; i<sourceDoc.pageItems.length;i++)
      {
      if (sourceDoc.pageItems[i].note == "Date") 
      {
      dateField = sourceDoc.pageItems[i];
      }
      if (sourceDoc.pageItems[i].note == "Time") 
      {
      timeField = sourceDoc.pageItems[i];
      }
      if (sourceDoc.pageItems[i].note == "Version") 
      {
      theVersionNumber = sourceDoc.pageItems[i].contents;
      }
      if (sourceDoc.pageItems[i].note == "Ops Component Code")
      {
      opsVersionCode = sourceDoc.pageItems[i].contents;
      }
    
      }
      if (theVersionNumber == versionFromName)
      {
      if (opsVersionCode == opsFromName)
      {
      if (dateField == null)
      {
      alert('No tagged date field found. Tag field and try again.')
      }
      else
      {
      dateField.contents = TodayDate()
      timeField.contents = TodayTime()
      OLtargetFile = this.getTargetFile(sourceDoc.name, '.pdf', destFolder);
      sourceDoc.saveAs( OLtargetFile, options)
      // alert( 'Documents saved as PDF' );
      }
      }
      else
      {
      alert('Ops component code in boiler does not match file name or is not tagged. Please correct and try again.')
      }
      }
      else
      {
                    
      alert('Version number in boiler does not match file name or is not tagged. Please correct and try again.')
      }
      }
      else 
      {
      alert('User aborted')
      }
    
      }
      else
      {
      throw new Error('There are no document open!');
      }
    }
    catch(e) {
      alert( e.message, "Script Alert", true);
    }
    
    
    /** Returns the options to be used for the generated files.
      @return PDFSaveOptions object
    */
    function getOptions()
    {
    
    
    
    
    
      // Create the required options object
      var options = new PDFSaveOptions();
      // See PDFSaveOptions in the JavaScript Reference for available options
      options.pDFPreset = "AZ"
    
    
      // For example, uncomment to set the compatibility of the generated pdf to Acrobat 7 (PDF 1.6)
      // options.compatibility = PDFCompatibility.ACROBAT7;
    
      // For example, uncomment to view the pdfs in Acrobat after conversion
      // options.viewAfterSaving = true;
    
      return options;
    }
    
    
    function abortFunction(){
    
      modUI = null;
      dlg.hide();
      return null;
      }
    /** Returns the file to save or export the document into.
      @param docName the name of the document
      @param ext the extension the file extension to be applied
      @param destFolder the output folder
      @return File object
    */
    function getTargetFile(docName, ext, destFolder) {
      var newName = "";
    
    
      // if name has no dot (and hence no extension),
      // just append the extension
      if (docName.indexOf('.') < 0) {
      newName = docName + ext;
      } else {
      var dot = docName.lastIndexOf('.');
      newName += docName.substring(0, dot);
      newName += ext;
      }
    
      // Create the file object to save to
      var myFile = new File( destFolder + '/' + newName );
    
      // Preflight access rights
      if (myFile.open("w")) {
      myFile.close();
      }
      else {
      throw new Error('Access is denied');
      }
      return myFile;
    }
    
    
    function TodayDate(){
      var Dateformat = "dd mm yyyy";
      nameMonths = true;
    
    
       var monthNames = ["January","February","March","April","May","June","July","August","September","October","November","December"];
       var Today = new Date();
       var Day = Today.getDate();
       if(nameMonths == true){
       var Month = monthNames[Today.getMonth()];
       } else {
       var Month = Today.getMonth() + 1;}
    
       var Year = Today.getYear();
       var PreMon = ((Month < 10) ? "0" : "");
       var PreDay = ((Day < 10) ? "0" : "");
       var Hour = Today.getHours();
       var Min = Today.getMinutes();
       var Sec = Today.getSeconds();
       if(Year < 999) Year += 1900;
       var theDate = Dateformat.replace(/dd/,PreDay+Day);
       theDate = theDate.replace(/mm/,PreMon+Month);
       theDate = theDate.replace(/d/,Day);
       //theDate = theDate.replace(/m/,Month);
       theDate = theDate.replace(/yyyy/,Year);
       theDate = theDate.replace(/yy/,Year.toString().substr(2,2));
       if(Hour==0){
      Hour = "12";
      theDate = theDate.replace(/XX/,"AM");
       }else if(Hour>12){
       Hour = (Hour-12);
       theDate = theDate.replace(/XX/,"PM");
       }else{
       theDate = theDate.replace(/XX/,"AM");
       }
       var preSec = ((Sec < 10) ? "0" : "");
       var preHour = ((Hour < 10) ? "0" : "");
       var preMin = ((Min < 10) ? "0" : "");
       theDate = theDate.replace(/hr/,preHour+Hour);
       theDate = theDate.replace(/Mn/,preMin+Min);
       theDate = theDate.replace(/sc/,preSec+Sec);
       return theDate;
    }
    
    
    function TodayTime(){
      var Dateformat = "hr:Mn";
      nameMonths = false;
    
    
       var monthNames = ["January","February","March","April","May","June","July","August","September","October","November","December"];
       var Today = new Date();
       var Day = Today.getDate();
       if(nameMonths == true){
       var Month = monthNames[Today.getMonth()];
       } else {
       var Month = Today.getMonth() + 1;}
    
       var Year = Today.getYear();
       var PreMon = "";//((Month < 10) ? "0" : "");
       var PreDay = ((Day < 10) ? "0" : "");
       var Hour = Today.getHours();
       var Min = Today.getMinutes();
       var Sec = Today.getSeconds();
       if(Year < 999) Year += 1900;
       var theDate = Dateformat.replace(/dd/,PreDay+Day);
       theDate = theDate.replace(/mm/,PreMon+Month);
       theDate = theDate.replace(/d/,Day);
       theDate = theDate.replace(/m/,Month);
       theDate = theDate.replace(/yyyy/,Year);
       theDate = theDate.replace(/yy/,Year.toString().substr(2,2));
       if(Hour==0){
      Hour = "12";
      theDate = theDate.replace(/XX/);
       }else{
       theDate = theDate.replace(/XX/);
       }
       var preSec = ((Sec < 10) ? "0" : "");
       var preHour = ((Hour < 10) ? "0" : "");
       var preMin = ((Min < 10) ? "0" : "");
       theDate = theDate.replace(/hr/,preHour+Hour);
       theDate = theDate.replace(/Mn/,preMin+Min);
       theDate = theDate.replace(/sc/,preSec+Sec);
       return theDate;
    }
    

    You can target the layer to search, add a line before you right pageitems loop, and then change the new target in your loop

      var targetLayer = sourceDoc.layers['Legend']; // ** added
    
      for(i=0; i		   
  • Compensation only specific security and not all

    Ours is a planning application. We are at version 11.1.2.0

    This question concerns the safety of level/Dimension member. We have defined manually security for all dimensions, except 2 in planning. For two dimensions that have a lot of members, that is, the product and the Customer dimension, we plan of loading files of fresh security twice a month by using the ImportSecurity.cmd utility.

    I know that SL_CLEARALL clears all the security. But I wanted to know if there was a way I could just remove security specific rather than anything clear and load again. So I want to clear security for product and customer dimensions than twice a month and want to reload with fresh security file each month. Is this possible? In this way, I want to just make sure that even if there are changes to the old security file, it is in phase.

    Can someone give me any ideas on how this can be done? All entries are appreciated.

    Looking forward to suggestions...
    ~ Hervé

    Yes, it erases the safety of both forms.

    HTH-
    Jasmine.

Maybe you are looking for

  • How to copy a new on an existing user.js in profile

    HelloI'll shut up deploy Firefox on many computers at once.Computers now have Firefox 14 on this and people work with it well.I ve it deployed with the determination of changes in the user.js.Now I have to uninstall the 14 Firefox and install Firefox

  • Temporarily white lines on the screen

    Hello The last two days, I experienced some temporary white horizontal lines on the screen of my Macbook Pro. They appear for seconds, as a kind of static electricity in half top of the screen. Any suggestions for what this could be? I looked in this

  • HP Pavilion Notebook PC g6: the upgrade of PC hard drive laptop HP Pavilion g6 - model no C4M01EA

    Hello I want to upgrade a hard drive of my laptop to 250 GB SSD drive. Did anyone of you has an idea about this? Disc specification hard existing is as below. hard drives of 6.35 cm (2.5 in) 9.5 mm (.37 inches) and 7.0 mm (.28 in.) thick Serial ATA (

  • Docfolderpaths missing in regedit (vista)

    Please help - miss me the My Documents folder and all the advice of the forum that I looked at showed me regedit, but DOCFOLDERPATHS is not.  I'm somewhat computer savvy, but I really don't like messing around with the registry.  How can I return thi

  • Cursor to burst around.

    When I type my cursor suddenly somewhere else, and I have to click on it, put it back and retype. and delete what I typed in the place, she appeared, how do I fix. I have Vista and wonder if he has the problem or there at - it a known solution for th