开发者

Add a 0 to the end of a decimal number to make sure it's always 2 decimals?

开发者 https://www.devze.com 2022-12-27 13:24 出处:网络
I am using the following code to work out an inc and ext VAT price: $(\'#totalexvat\').text开发者_Go百科(totalprice);

I am using the following code to work out an inc and ext VAT price:

$('#totalexvat').text开发者_Go百科(totalprice);
var vat = totalprice / 100 * 17.5;
vat = roundNumber(vat,2);
$('#totalincvat').text(totalprice-vat);

Sometimes I get .3 or .9 instead of what I would like to be .30 or .90 because it's money, is there a way to do this?


You may want to look at this: http://code.google.com/p/jquery-numberformatter/ since you're using jQuery already.


try toFixed

0

精彩评论

暂无评论...
验证码 换一张
取 消