Be seen. Boost your questionâ€™s priority for more expert views and faster solutions

I'm feeding a variable from a database which comes in with three decimal places. But I want to redisplay the variable as an integer. How do I do that?

1 Solution

Short description is here:

http://www.javascripter.net/faq/mathfunc.htm

http://www.mediacollege.com/internet/javascript/number/round.html

<script language="javascript" type="text/javascript">

function roundNumber() {

var numberField = document.roundform.numberf

var rnum = numberField.value;

var rlength = 2; // The number of decimal places to round to

if (rnum > 8191 && rnum < 10485) {

rnum = rnum-5000;

var newnumber = Math.round(rnum*Math.pow(1

newnumber = newnumber+5000;

} else {

var newnumber = Math.round(rnum*Math.pow(1

}

numberField.value = newnumber;

}

</script>

<form name="roundform">

<input type="text" name="numberfield">

<input type="button" value="Round" onClick="roundNumber();">

</form>

http://www.jsmadeeasy.com/javascripts/Calculators/Round/index.htm

http://www.javascriptkit.com/script/script2/roundnum.shtml

R.K

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Tackle projects and never again get stuck behind a technical roadblock.

Join Now
Math.round(x)

Using it, any supplied argument is rounded off to the nearest integer, and using the ".5" up rule. For example:

Math.round(25.9) //returns 26

Math.round(25.2) //returns 25

Math.round(-2.58) //returns -3