2

I want to round both 130.68(greater than or equals 130.5) and 131.32(less than 131.5) values to 131.

ssrp
  • 1,008
  • 5
  • 16
  • 34
  • 2
    [Math.round()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round) – Satpal Apr 04 '14 at 10:20
  • 1
    possible duplicate of [How do I convert a number to an integer in Javascript?](http://stackoverflow.com/questions/596467/how-do-i-convert-a-number-to-an-integer-in-javascript) – Sani Singh Huttunen Apr 04 '14 at 10:23

4 Answers4

6

Use Math.round()

Math.round(130.68); // return 131
Math.round(131.32); // return 131

Fiddle Demo

Tushar Gupta - curioustushar
  • 56,454
  • 22
  • 99
  • 107
2

You need to use Math.round(), In example below both statement will alert 131

alert(Math.round(130.68));
alert(Math.round(131.32));

DEMO

Satpal
  • 129,808
  • 12
  • 152
  • 166
1

You can use Math.round

num=130.68; 
Math.round(num);
1

use this link:

Use Math.round()

sathya
  • 1,384
  • 2
  • 14
  • 26