Skip to content

Instantly share code, notes, and snippets.

@denisz
Created October 12, 2018 09:35
Show Gist options
  • Save denisz/9f11fe70732723e28e8afa979d2ca80e to your computer and use it in GitHub Desktop.
Save denisz/9f11fe70732723e28e8afa979d2ca80e to your computer and use it in GitHub Desktop.
$(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