• Products
    • Isadora
    • Get It
    • ADD-ONS
    • IzzyCast
    • Get It
  • Forum
  • Help
  • Werkstatt
  • Newsletter
  • Impressum
  • Dsgvo
  • Press
  • Isadora
  • Get It
  • ADD-ONS
  • IzzyCast
  • Get It
  • Press
  • Dsgvo
  • Impressum

Navigation

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Tags

    Round to X number of decimals, using Javascript

    How To... ?
    1
    1
    993
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • DusX
      DusX Tech Staff last edited by

      I was just answering a support request, where I sent the user a piece of Javascript code I use...

      and thought that I should share it here:

      It takes in a float and outputs it rounded to the number of decimals set in the second input.

      ![](http://troikatronix.com/troikatronixforum/discussion/download/2642/jsround.jpg)
      //input 1 = the float val
      //input 2 = the number of decimal places to round [0-4]  MUST BE INT
      
      function main()
      {
      	function Nrnd(num, places){ 
      		return +(Math.round(num + "e+" + places) + "e-" + places);
      	}
      
      	R = Nrnd(arguments[0],arguments[1]);
      	return R;
      }
      

      d96ed9-jsround.jpg

      Troikatronix Technical Support

      • New Support Ticket Link: https://support.troikatronix.com/support/tickets/new
      • My Add-ons: https://troikatronix.com/add-ons/?u=dusx
      • Profession Services: https://support.troikatronix.com/support/solutions/articles/13000109444-professional-services

      Running: Win 11 64bit, i7, M.2 PCIe SSD's, 32gb DDR4, nVidia GTX 4070 | located in Ontario Canada.

      1 Reply Last reply Reply Quote 0
      • First post
        Last post