I already realize the inherent dangers in working with float values but I've never really run into this problem until now..
Here's the code for this particular problem.
Basically I get two float values from the interface and run them through the equation above in bold. I have the same program in a command line type of program coded in C and my calculations come up just fine but whenever I do it in my Cocoa program, the pressureAltitude result comes up like .000000001 off or some silly little number.
Is there a way to fix this? I've fixed it indirectly by adding a number formatter to that text field that it displays in and just rounding up but I'd like to know if I can fix the number itself.
Here's the code for this particular problem.
Code:
-(IBAction) calculatePresAlt: (id) sender
{
float pressureAltAmount;
calculator = [[TakeoffLandingCalc alloc] init];
[calculator setAltimeterSetting: [altimeterField floatValue]];
[calculator setFieldElevation: [elevationField floatValue]];
pressureAltAmount = [calculator [I]calcPressureAltitude[/I]];
[pressureField setFloatValue: pressureAltAmount];
}
**Here is the calcPressureAltitude method**
-(float) [I]calcPressureAltitude[/I]
{
[B] pressureAltitude = (29.92 - altimeterSetting) * 1000.0 + fieldElevation;
[/B] return pressureAltitude;
}
Basically I get two float values from the interface and run them through the equation above in bold. I have the same program in a command line type of program coded in C and my calculations come up just fine but whenever I do it in my Cocoa program, the pressureAltitude result comes up like .000000001 off or some silly little number.
Is there a way to fix this? I've fixed it indirectly by adding a number formatter to that text field that it displays in and just rounding up but I'd like to know if I can fix the number itself.