if(!isNaN(str){
//str is a number
//convert it to number
/for integer
var iStr = parseInt(str);
//for float
fStr = parseFloat(str);
}else{//not a number
//your processing
}
Khalid,
Thank you for your suggestions, it got me started. The final function looks like this:
function enforcePrecision(sValue, iPrecision, sDirection){
fValue = parseFloat(sValue); //Convert to number
if(!isNAN(value)){
var sPrecision = "1"
for(var i=0; i < iPrecision-1; i++){
sPrecision += "0"
}
iPrecision = parseInt(sPrecision);
fValue *= iPrecision; //Multiply by value
eval(value);
if(!sDirection){
fValue = Math.round(fValue); //Undefined direction
}
if(sDirection == "Down"){
fValue = Math.floor(fValue); //Round down
else
fValue = Math.ceil(fValue); //Round up
}
value /= iPrecision;
return value;
}
}
Bookmarks