So I am trying to learn how to divide fractions. I am confused why dividing variables gives the correct result, and dividing the numbers themselves gives an incorrect result. I have tried to searching on here and couldn't find anything relevant. Here is an image to show why I am talking about.

            Asked
            
        
        
            Active
            
        
            Viewed 140 times
        
    -1
            
            
         
    
    
        pewpew
        
- 700
- 2
- 9
- 32
- 
                    `1/3` is integer division, will give a result of `0` because of truncation. Did you mean `1.0/3.0` ? – AntonH Mar 16 '17 at 04:24
- 
                    1In the future, please don't post images of text. Copy-paste the text, as text, instead. – Some programmer dude Mar 16 '17 at 04:25
- 
                    Ok, thank you! will do! I understand now thank you! – pewpew Mar 16 '17 at 04:26
- 
                    1[don't put images of text](https://meta.stackoverflow.com/q/303812/995714) – phuclv Mar 16 '17 at 04:33
1 Answers
3
            The expression 1 / 3 is an integer expression. You divide two int values. That leads to truncation.
Try e.g. 1.0 / 3.0 instead.
 
    
    
        Some programmer dude
        
- 400,186
- 35
- 402
- 621
- 
                    1Just to be precise: it truncates towards zero, thus if one operand is negative, the result is actually higher than one might expect. – too honest for this site Mar 16 '17 at 06:01