Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

type conversion, float to int

Status
Not open for further replies.

stormbind

Technical User
Mar 6, 2003
1,165
GB
hi,

title says it all really. how do i convert a float into an int?

cheers.

--Glen :)

Memoria mihi benigna erit qui eam perscribam
 
Code:
int a;
float b = 3.141592654;

a = (int) b;

-kaht

Looking for a puppy?

[small]Silky Terriers are small, relatively odorless dogs that shed no fur and make great indoor pets.[/small]
 
That truncates the float, doesn't it?

You can use Math.round to get the nearest int, but remeber that you will always lose the decimal part.

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top