Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualHermanssoN

Posted 10 May 2013 - 12:25 PM

Hi.

If you write this:
 

float number = 1/4;

We know that 1/4 = 0.25, but we if use integers when dividing the reuslt will also be an integer. Integers can not hold decimal number, so it will round it to a whole number. e.g 0.

If you type:
 

float number = 1.0f / 4.0f;

now the operation will return a decimal number.

to sum it up:
 

float f1 = 1/4; // f1 is now 0
float f2 = 1.0f/4.0f; //f2 is now 0.25



#2HermanssoN

Posted 10 May 2013 - 12:24 PM

Hi.

If you write this:
 

float number = 1/4;

We know that 1/4 = 0.25, but we if use integers when dividing the reuslt will also be an integer. Integers can not hold decimal number, so it will round it to a whole number. e.g 0.

If you type:
 

float number = 1.0f / 4.0f;

now the operation will return a decimal number.

to sum it up:
 

int i = 1/4; // i is now 0
float f = 1.0f/4.0f; //f is now 0.25



#1HermanssoN

Posted 10 May 2013 - 12:23 PM

Hi.

If you write this:
 

float number = 1/4;

We know that 1/4 = 0.25, but we if use integers when dividing the reuslt will also be an integer. Integers can not hold decimal number, so it will round it to a whole number. e.g 0.

If you type:
 

float number = 1.0f / 4.0f;

now the operation will return a decimal number.

to sum it up:
 

int i = 1/4; // i is now 0
float f = 1.0f/4.0f; f is now 0.25


 


PARTNERS