简体   繁体   中英

Calculation in Javascript without rounding decimal numbers

Guys I got a text box wherein users may enter valid decimal numbers.

And later I have to do calculations with this decimal number without rounding it.

Currently I am working as

 var pricePerItemExVat = Math.round($("#InnerCaseWsp").val()) / Math.round($("#InnerCaseItemSellUnit").val());

How do I do the same without rounding the number ?

It looks like you used Math.round to get numbers from strings.

Just parse the strings to numbers using parseFloat :

var pricePerItemExVat = parseFloat($("#InnerCaseWsp").val()) / parseFloat($("#InnerCaseItemSellUnit").val());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM