Help for repeating dots(solved)

How I prevent repeating dots here?

//getting number with dot
$("#numbers #dot").click(function(){

dot= this.text;
if(number===""){
number=β€œ0”+dot;
}else{
number= number+dot;
}
resultDiv.val(number);

});

You could search number for occurrences of β€œ.” and only add the dot if it isn’t found. indexOf would work (returns -1 if not found), or you could evaluate via regular expression.

thank you. I solved it.

1 Like