views:

58

answers:

2

I am using the following code to come up with a number.

NSString *userNameOne = txtUserName.text;
double numOne = [userNameOne intValue];

double agedecade = numOne/10;
double betaage = 0.23260;
double meanage = 5.64301;
double one_age = agedecade - meanage;
double age_final_var =  one_age * betaage;

If the user input 55 into the numOne variable, the answer will be -.033264 using the above program.

However, if I do the same on a calculator I get -.033264126. I would like to get the extra three digits into my program. How do I get the missing three digits (...126) into my program above?

** I happen to be using this code in an iPhone App, saying this in case this changes things.

+3  A: 

Your problem is not in the double variable, but in the way you print it. Look at the function that prints it, and find a way to increase the amount of numbers after tghe decimal point.

Also, is it a typo, or again you have intValue instead of doubleValue? :>

Kornel Kisielewicz
yeah i asked this same time as i asked the other one regarding doubleValue. Will my data still be stored as the long decimal point?
HollerTrain
A: 
[NSString stringWithFormat:@"%.15g", age_final_var];
KennyTM