Liberator Liberator - 4 months ago 20
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:

42880


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

user parseInt function for it. Like below

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

You will get only Integer as output.