RSS Feed

Convert Float To Integer Java Android Studio

I have seen people asking how do I convert a float to integer. I have even seen people convert values to strings and back again.

This is an easy way to convert a float to integer. It is a simple matter of casting, like so…

float flt = 2.0f;
int  = 0i;

i = (int) flt;      // <— that is it!

The variable i is now = 2 and an integer.

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: