<ul id="mylist">
<li>my price:<span>29.95</span> €</li>
</ul>
$( document ).ready(function() {
$("#mylist li span").each( function() {
$(this).text( Number($(this).text()) * 1.03 );
});
});
I try to update a prize value by multiplying it with 1.03. The value should be rounded so that the result of this example is 30,85 . Could someone please help me?
I'll break this down into three steps:
Math.round
, multiplying our value by 100, and then dividing it by 100. This is a simple trick for proper place-rounding.""
to it..replace(".",",")
to change the point to a comma.JSFiddle: https://jsfiddle.net/vLxj8bfs/2/
This could really be written in one line, but for explanation and readability, I've broken the values down a bit.