Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

HannKett

macrumors member
Original poster
Feb 25, 2012
70
0
Europe
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
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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".
 

MorphingDragon

macrumors 603
Mar 27, 2009
5,160
6
The World Inbetween
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

Nevermind, robbie got it.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.