Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Divide a integer and get decimal answer

i currently have an integer int i and its value is 60 i wish to divide this by 100 to get 0.60 but i cannot do this please help

int i = 60;
int x = 60 / 100; // Dosen't work should be 0.60 instead returns 0
like image 826
user393273 Avatar asked May 04 '11 17:05

user393273


People also ask

How do you get rid of decimals when dividing?

There cannot be decimals in the divisor; therefore, remove the decimal point from the divisor and add as many zeros to the dividend as there are digits after the decimal point. In this case, we have to add only one zero.


1 Answers

divide by 100.0f and return result into a float.

like image 91
DavidN Avatar answered Oct 02 '22 06:10

DavidN