如何将价格限制为2个小数点

Zin*_*nox 2 javascript jquery decimal tofixed

我的Html

<div class="product-line">              
                    <a href="#" alt="close" class="btn-close" title="Remove"><img alt="remove" src="img/close.png" /></a>
                    <input class="input-text" name="product-code" type="text" placeholder="Product Code" />
                    <input class="input-text" name="product-quantity" type="text" placeholder="Quantity" />
                    <input class="input-text" name="product-discript" type="text" placeholder="Discription of Product" disabled />
                    <label class="label-sign">&pound;</label>
                    <input class="input-text price" name="product-price" type="text" placeholder="RRP Price" disabled />
                        <br>
</div>
Run Code Online (Sandbox Code Playgroud)

我的JS代码行

price = $(this).parent("div.product-line").find("input[name=product-price]").val( Number(price).toFixed(2)  *  quantity )
Run Code Online (Sandbox Code Playgroud)

基本上,如果我乘以例如40.2数量3,我得到类似120.600000000 ....我怎么能将它限制为2小数点.

数据通过JSON(由其他人制作)传入.

我是一名JS新手

ade*_*neo 6

只需移动toFixed到乘法的输出即可.

.val( ( Number(price) *  quantity ).toFixed(2) );
Run Code Online (Sandbox Code Playgroud)