Home javascript rounding to hundredths

rounding to hundredths




In general, there is a F-I for rounding to hundredths


var rounded = function (Number) {
  Return Math.round (ParseFloat (Number) * 100) / 100;

works with a bang with single values, but I have a lot of addition and subtraction operations and subtracting n the number of values, and sometimes skip the values ​​of type 892.299999999 and so on. The question is whether there is a more versatile option for rounding

Answer 1, Authority 100%

maybe: https://jsfiddle.net/ionden/eqj36j1w/

var rounded = function (Number) {
  Return + Number.tofixed (2);
Console.log (Rounded (29.49999)); //29.5.
Console.log (Rounded (15.75621900432)); //15.76

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions