Number formatting with 2 decimal places on a textbox populated by a variable [duplicate]

21 hours ago 3
ARTICLE AD BOX

First, add the closing brace for the function definition. Then, use Number#toFixed to get a specific number of decision places in the string representation.

function calculateSum() { if (document.getElementById("unloadedcheck").checked) { document.getElementById("unloadedtotal").value = ( document.getElementById("unloadedrate").value * document.getElementById("unloadedmiles").value ).toFixed(2); } else { document.getElementById("unloadedtotal").value = "0.00"; } }

Unmitigated's user avatar

3 Comments

That breaks it. It won't populate the field after making that change.

2026-04-07T00:53:19.697Z+00:00

2026-04-07T00:58:01.713Z+00:00

An assignment operator won't populate the field? Look again.

2026-04-07T01:39:02.107Z+00:00

Read Entire Article