Number.prototype.money = function(c, d, t){ var n = this, c = isNaN(c = Math.abs(c)) ? 2 : c, d = d == undefined ? "." : d, t = t == undefined ? "," : t, s = n < 0 ? "-" : "", i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0; return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : ""); }; function getprice(x) { var r = 0; var p, q; x = x.replace("," ,""); x = x.replace(" " ,""); x = parseInt(x); var ss = ""; if (x < 0) { return "Please Input Property Value"; } if (x <= 125000) { return "No stamp duty tax for property under 125K!
"; } q = x >= 250000 ? 125000 : x - 125000; p = q * 0.02; r += p; ss += "£125,000.01 - £250,000, 2% " + q.money(2, '.', ',') + "GBP X 2% = Tax " + p.money(2, '.', ',') + " GBP
"; if (x >= 250000) { q = x >= 925000 ? (925000 - 250000) : x - 250000; p = q * 0.05; r += p; ss += "£250,000.01 - £925,000 5% " + q.money(2, '.', ',') + "GBP X 5% = Tax " + p.money(2, '.', ',') + " GBP
"; } if (x >= 925000) { q = x >= 1500000 ? (1500000 - 925000) : x - 925000; p = q * 0.1; r += p; ss += "£925,000.01 - £1,500,000 10% " + q.money(2, '.', ',') + "GBP X 10% = Tax " + p.money(2, '.', ',') + " GBP
"; } if (x > 1500000) { q = x - 1500000; p = q * 0.12; r += p; ss += "£1,500,000.01, 12% " + q.money(2, '.', ',') + "GBP X 12% = Tax " + p.money(2, '.', ',') + " GBP
"; } ss += "Total " + r.money(2, '.', ',') + " GBP Stamp Duty, Effective Rate is " + (r/x*100).toFixed(2) + "%
"; return ss; } document.getElementById("tax1").innerHTML = getprice(document.getElementById("price1").value);