Having decided to learn myself Cocoa I wrote a simple calculator in Java and everything worked fine except for whenever I tried to use decimal numbers. The result is almost right but not exactly, e.g. 1.1 + 1 would become 2.099999... Oh, well I thought, must be something wrong with my Java-knowledge. So I tried to write a simple program in Objective-C that just adds two numbers and to my surprise the same thing happens, i.e. 1 +1 becomes 2 but 1.1 + 1 becomes 2.099999904632568. I include my source code below and I hope someone can shed some light on it as I really haven't got a clue what could be wrong...
---test.h
#import <Cocoa/Cocoa.h>
@interface test : NSObject
{
IBOutlet id number1;
IBOutlet id number2;
IBOutlet id sum;
}
- (IBAction)calculate

id)sender;
@end
---test.m
#import "test.h"
@implementation test
- (IBAction)calculate

id)sender
{
float value1, value2, calculation;
value1 = [number1 floatValue];
value2 = [number2 floatValue];
calculation = value1 + value2;
[sum setFloatValue:calculation];
}