Click to See Complete Forum and Search --> : float and ceail


phil@philspeakm
03-05-2003, 03:32 AM
i have just created a bmi calculator - the answers come as floating point numbers, if theay are **.5 or below they should get rounded down and **.6 or above, rounded up - i know how to round down and up but not how to check and see if the number after the . is 5 or 6, anyone got any ideas,
much appriciated, Phil

gil davis
03-05-2003, 06:16 AM
I think you meant "ceil".<script>
var i = 123.5;
alert(i - Math.floor(i));
</script>

khalidali63
03-05-2003, 06:29 AM
This should be fairly simple comparison statement.There may be multiple approaches with which you can acquire this.
first separate the value after the decimal
var num = (22.7).toString()
var x = parseInt(num.substring(num.indexOf(".")+1,num.length))
if(x<=6){
alert(x)
}else{
alert(x+", must not be greater then .6")
}

Hope this gives you an idea

Cheers

Khalid