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

Android

Marcio Almeida
Marcio Almeida
4,579 Points

Math.round

Hi,

I'm trying to round a double number to an integer, and i'm doing like this

public double getWindSpeed() {
    return (int)Math.round(35.23);
}

but I dont know why is returning "35.0" and not "35"

Thank you

Marcio Almeida
Marcio Almeida
4,579 Points

Hi,

The problem is not with the method, I dont now why in my activity always show a decimal number.

1 Answer

Daniel Hartin
Daniel Hartin
18,106 Points

Hi Marcio

As the data type int doesn't support decimal numbers casting to an int will always results in a whole number. The problem is the method where you have defined it to return a double , if you change this to int you should be fine.

Hope this helps Daniel