Liberator Liberator - 1 year ago 121
jQuery Question

Javascript ParseFloat to autofill without decimals

I have some inputs in a HTML form using javascript to autofill the inputs on changes

The problem is that the follow code show decimals longer decimals like this 42880.34623465464356435634 The code is:

thetotal.value = parseFloat(total.value) * (1.00/1.19);

This code get the price less taxes from the total and it works, but it show me the decimals...

What I need is the price to be in the example:


Without dots or commas . or , like 42.880 or 42,880 and absolutly not 42880.34623465464356435634

I only want to show 42880

Tried with .round like this:

thetotal.value = parseFloat(total.value) * (1.00/1.19).round(2);

.round(2) but for some reason the addEventListener stop working for this input when using .round(2)

Answer Source

user parseInt function for it. Like below

thetotal.value = parseInt(parseFloat(total.value) * (1.00/1.19));

You will get only Integer as output.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download