• 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
    1192
    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 Izzy Guru 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 Professional Services
      https://troikatronix.com/professional-services

      ๐ŸŽซ Support Tickets
      https://support.troikatronix.com/support/tickets/new

      ๐Ÿ’ป Add-ons
      https://troikatronix.com/add-ons/?u=dusx

      ๐Ÿงช GitHub Projects
      https://github.com/rwebber

      ๐Ÿ–ฅ๏ธ Win11 | i7 | RTX 4070 | 32GB RAM | Ontario, Canada

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