Search Unity

divitionof two int to a float number

Discussion in 'Scripting' started by kordou, Apr 4, 2018.

  1. kordou

    kordou

    Joined:
    May 16, 2017
    Posts:
    13
    hi,
    i have a very weird problem.

    i have two int that i divide them inside a subroutine and store the ratio to a float number. my problem is that after the division my int numbers changes to something complete different

    Code (CSharp):
    1. int width,height;
    2. float ratio;
    3.  
    4. void Start(){
    5. width =800;
    6. height = 530;
    7.  
    8. giveratio(width,height);
    9. }
    10.  
    11. void giveratio(int width, int height){
    12. ratio = (float)width/float(height);
    13. }
    14.  
    After running this i get :

    ration = 1.5
    and then the
    width becomes 2500!
    and height 1766!

    what i am doing wrong here ?


    UPDATE

    found the error it was in onther part