function numberFormat(nStr){ nStr += ''; x = nStr.split('.'); x1 = x[0]; x2 = x.length > 1 ? '.' + x[1] : ''; var rgx = /(\d+)(\d{3})/; while (rgx.test(x1)) x1 = x1.replace(rgx, '$1' + ',' + '$2'); return x1 + x2; } function stripNonNumeric( str ){ str += ''; var rgx = /^\d|\.|-$/; var out = ''; for( var i = 0; i < str.length; i++ ){ if( rgx.test( str.charAt(i) ) ){ if( !( ( str.charAt(i) == '.' && out.indexOf( '.' ) != -1 ) || ( str.charAt(i) == '-' && out.length != 0 ) ) ){ out += str.charAt(i); } } } return out; } function serbestpiyasaHesapla(){ miktar = stripNonNumeric(document.serbestpiyasaThemeForm.serbestpiyasaMiktar.value); kur1 = document.serbestpiyasaThemeForm.serbestPiyasaKur1.value; kur2 = document.serbestpiyasaThemeForm.serbestPiyasaKur2.value; carpan = miktar / kur2; tutar = carpan * kur1; document.serbestpiyasaThemeForm.serbestpiyasaMiktar.value = numberFormat(miktar); document.serbestpiyasaThemeForm.serbestpiyasaTutar.value = numberFormat(tutar.toFixed(2)); }