Nishant Rambhojun
Nishant Rambhojun

Reputation: 77

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 ?

Upvotes: 0

Views: 133

Answers (1)

Denys Séguret
Denys Séguret

Reputation: 382150

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());

Upvotes: 3

Related Questions