Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: Another "how to round" question

1. ## Another "how to round" question

I have read the rounding forums but am still unsure how to incorporate it into my code.

function calculateResult(){
var pcintX = document.form1.x.value;
var pcintY = document.form1.y.value;
var pcintZ = ((pcintX * pcintX)*90.69)/(pcintY * pcintY);
document.form1.z.value = pcintZ;
return false;
}

I need the calculation to round the pcintZ value to 2 decimal places.

Any help on how I could do this?

Thank you

• Rounding something to two digits is the same as multiply it by 100, rounding it to an integer, then dividing it by 100 again. Like this:
Code:
`pcintZ = Math.round(pcintZ * 100) / 100;`

• If you want it to always display two decimals (instead of dropping ending zeroes), you can have a look in the FAQ. You can find a function for doing that in there.

• Great thank you! - Problem solved.

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•