Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

How do I display results in box that are unrounded and 4 decimal places?

Here is the line of code that generates the value that is displayed, and i've tried to change the math.round to math.abs that displays more than 4 decimals which is what i really need.

document.numbersAB.school_rate_box.value=Math.round(school_rate*100000)/100

Here is how the input box is coded <input type="text" name="school_rate_box" readonly>

thanks for any advice on this.

1 Answer

Steven Parker
Steven Parker
243,656 Points

You're close. But if you don't want it rounded, use "trunc" instead of "round". And if you don't want to otherwise change the value, multiply and divide by the same value, picked for the precision.

So for 4 digits:

Math.trunc(school_rate * 10000) / 10000

I'm not familiar with this syntax: "document.numbersAB.school_rate_box.value" — how does that address the element?