-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWTFormatter.m
32 lines (27 loc) · 898 Bytes
/
WTFormatter.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#import "WTFormatter.h"
@implementation WTFormatter
- (NSString *)stringForObjectValue:(id)anObject
{
if (![anObject isKindOfClass:[NSNumber class]]) {
return nil;
}
return [NSString stringWithFormat:@"%.4f", [anObject floatValue]];
}
- (BOOL)getObjectValue:(id *)obj forString:(NSString *)string errorDescription:(NSString **)error
{
float floatResult;
NSScanner *scanner;
BOOL returnValue = NO;
scanner = [NSScanner scannerWithString: string];
// [scanner scanString: @"$" intoString: NULL]; //ignore return value
if ([scanner scanFloat:&floatResult] && ([scanner isAtEnd])) {
returnValue = YES;
if (obj)
*obj = [NSNumber numberWithFloat:floatResult];
} else {
if (error)
*error = NSLocalizedString(@"CouldnÕt convert to float", @"Error converting");
}
return returnValue;
}
@end