Created
October 12, 2018 09:35
-
-
Save denisz/9f11fe70732723e28e8afa979d2ca80e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function(){ | |
function toFixed(x, n) { //x - число, n - количество знаков | |
if(isNaN(x) || isNaN(n)) return false; | |
var m = Math.pow(10,n); | |
return Math.round(x*m)/m; | |
} | |
var items = document.querySelectorAll("*[data-price]"); | |
for (var i = 0, l = items.length; i < l; i++) { | |
var fix = parseInt(items[i].getAttribute("data-fixed"), 10) || 0; | |
var base = parseFloat(items[i].getAttribute("data-price")) || 1; | |
var price = base * 70; | |
items[i].innerHTML = numberFormatter("# ###.", toFixed(price, fix)) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment