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

Adding decimal values

let a = 4.0; let b = 4.0; and we have to print the sum of these numbers as 8.0 using javascript. But every time i perform the addition it always print 8 as result not 8.0.

1 Answer

vincent batteast
vincent batteast
57,412 Points

ok This was a good question and I had to look it up but use toFixed()

let a = 4.0; let b = 4.0;
let answer = a + b;
answer.toFixed();

I hope this help but it you need more help you have to give more code.
read this https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed

Yeah i also got the answer after some research. I want to delete the question but i don't know how to do that.