which type I have to use Double or Float?? Help

Discussion in 'iOS Programming' started by al7zn22, Sep 12, 2010.

  1. al7zn22 macrumors newbie

    Joined:
    Nov 13, 2006
    #1
    Hey guys I have try many type of number when I try to divide two numbers.

    For example:
    if I have : x = 1, and y= 1000
    and I want to get a result of
    0.001 if i did x/y
    and
    1000 if i did y/x

    I try using @"%f" but it does not show it in the right way..
    I know if I use @"%0.3f" it will show the answer as 0.001
    but what if I have y = 10000? the answer will be 0.000
    and in my case if I did y/x the answer will be 1000.000
    and I only want to show the 1000

    how could I do it?
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    As chown33 likes to say, "we can't debug descriptions". Please provide some code.

    Also, be aware that the issue probably doesn't lie in the type of the value stored, but rather in the way you are going about outputting that value.
     
  3. al7zn22 thread starter macrumors newbie

    Joined:
    Nov 13, 2006
    #3
    This is my code and the result for each code is below it.

    float total = 1*1000;
    lable.text = [NSString stringWithFormat:mad:"%f",total];
    ---------------------------------------------
    the result comes to : 1000.000000
    and the output I want is: 1000
    ---------------------------------------------


    float total = 1/1000;
    lable.text = [NSString stringWithFormat:mad:"%f",total]
    ---------------------------------------------
    the result comes to: 0.001000
    and I want the result to be 0.001
    ---------------------------------------------


    float total = 1/100;
    lable.text = [NSString stringWithFormat:mad:"%f",total]
    ---------------------------------------------
    the result comes to: 0.010000
    and I want the result to be 0.01
    ---------------------------------------------
     
  4. al7zn22 thread starter macrumors newbie

    Joined:
    Nov 13, 2006

Share This Page