PDA

View Full Version : need some kind of rounding algorithm


umen
01-03-2003, 12:01 PM
Hello
i trying to find way to round numbers what is mean is this :
say i have the number : 231 so i like to round it to 300
or if ihave :
2 round it to 10
92 round it to 100
7111 round it to 8000
10001 round it to 20000

need some idea please
thanks for the help

Bosko
01-03-2003, 12:33 PM
Use Math.round(number); .

Btw,round 2 to 10??

Algorithm
01-03-2003, 12:37 PM
The function below rounds a number up to any number of signifigant digits. Hope it helps.function roundUpToSigDigit(num,digits){
var p=Math.pow(10,(Math.floor(num).toString().length-digits));
return p*Math.ceil(num/p);
}

umen
01-03-2003, 12:57 PM
Yes!
very nice idea Algorithm , is it yours idea?
thanks any way...