-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathERRFormatter.m
40 lines (34 loc) · 1.02 KB
/
ERRFormatter.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
33
34
35
36
37
38
39
40
//
// ERRFormatter.m
// AgeFinder
//
// Created by Peter Appel on 06/07/2009.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import "ERRFormatter.h"
@implementation ERRFormatter
- (NSString *)stringForObjectValue:(id)anObject
{
if (![anObject isKindOfClass:[NSNumber class]]) {
return nil;
}
return [NSString stringWithFormat:@"%.1f", [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