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

Java

Java convert double to int

so i am making a small test app to convert a monetary amount into dollar bills and coins. when i run the code the final values are long decimals because they are doubles, yet they need to be integers. how can i convert a double amount to an integer in java?

1 Answer

You can use the double object's intValue() method.

Double someNumber = 2234234;
Integer anInteger = someNumber.intValue();