Algo question for the math folks out there

Discussion in 'Mac Programming' started by HannKett, Mar 6, 2012.

  1. macrumors member

    Joined:
    Feb 25, 2012
    Messages:
    70
    Location:
    Europe
    #1
    Hello,

    I have a weird problem, and I can not think straight so I need some input on this one algo :)

    I have a slider with values of 1-9, now what I want to use the floats for is that I get 1.0 - 9.0 in float values that I have rounded off so there are no 1.5 and 3.7 and so.

    Now I want to reverse the 1.0 to use in multiplication as a 0.9 and 2.0 as 0.8 and so on. but I cant for some reason come up with how to do that.

    Maybe I need more sleep, but it is like when you forgot a name and word but you have it on the back of your tongue..

    so please help me and relief my mental pain
     
  2. Moderator

    robbieduncan

    Staff Member

    Joined:
    Jul 24, 2002
    Messages:
    24,480
    Location:
    London
    #2
    1) The first part is easy: cast to int then back to float (assuming you are using C types rather than NSNumber)

    2) It's not clear by what you mean by "reverse". It appears you mean "divide by 10 then subtract that result from 1.0".
     
  3. macrumors member

    Joined:
    Feb 25, 2012
    Messages:
    70
    Location:
    Europe
    #3
    LOL :) hahah thanks man :p (ashamed I am)

    I need stronger coffe !
     
  4. macrumors 603

    MorphingDragon

    Joined:
    Mar 27, 2009
    Messages:
    5,161
    Location:
    The World Inbetween
    #4
    Nevermind, robbie got it.
     

Share This Page