idontknowhow idontknowhow - 1 year ago 56
Javascript Question

How can I round to whole numbers in JavaScript?

I have the following code to calculate a certain percentage:

var x = 6.5;
var total;

total = x/15*100;

// Result 43.3333333333

What I want to have as a result is the exact number
and if the total is
it should be rounded to

Is there way to do this in JavaScript?

Answer Source

Use the Math.round() function to round the result to the nearest integer.