-5

I'm trying to round off the decimal. Below are the scenarios

Entered Value - 56.6
Round off Value - 57

Entered Value - 56.7
Round off Value - 57

Entered Value - 56.8
Round off Value - 57

But same thing when i try to round of 56.3/56.2/56.4, same value is displaying.

When i try 56.1 to 56.4, i'm getting the same value itself. But when i try from 56.5 to 56.9 value is rounding off to 57

Entered Value - 56.3
Round off Value - 56.3
Expected Value - 57

i've tried below code to round of

parseFloat(value).toFixed();
Math.round(value)

How to actually execute all the scenarios of to round off?

Matarishvan
  • 2,382
  • 3
  • 38
  • 68

1 Answers1

3

Math.round() rounds to the nearest integer. So it rounds down for fractions below .5, and rounds up for fractions above .5.

If you always want to round up, use Math.ceil().

value = 56.3;
console.log(Math.ceil(value));
Barmar
  • 741,623
  • 53
  • 500
  • 612