math - Javascript Rounding to the nearest 2 decimal (however 5 rounds down) -


All my values ​​are coming back from the server as 3 decimal places. I have to score 10, 2 decimal places in the nearest place, in the past. Grip from decimal (18,2) decimal (18,3) is that when it is a 5, then it needs to be rounded.

I need to do this in javascript: D

I can not guarantee that 3 decimal places will return, this is the maximum. ex 4.494 - & gt; 4.4 9 ** East 4.4 9 5 - & gt; 4.4 9 ** East 4.496 - & gt; 4.50

It seems that you only want special rounding, where the final digit is 5, so the exam is for him and in those cases differently Do the goals from: PreRound function ends in myRound (n) {// if .nn5, then round if (/ \. \ D \ d5 $ /. Test ('' + N)) {n = Math.floor (n * 100) / 100; } // apply normal spherical return n.toFixed (2); } Console.log (myRound (4.494)); // 4.49 console.log (myRound (4.495)); // 4.49 console.log (myRound (4.496)); // 4.50

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -