Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jonathan Mitchell
committed
Feb 16, 2015
1 parent
e7fab71
commit 214bc81
Showing
5 changed files
with
98 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// TSPageNumberFormatter.h | ||
// PDFPageBuilder | ||
// | ||
// Created by Jonathan Mitchell on 16/02/2015. | ||
// Copyright (c) 2015 Thesaurus Software. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface TSPageNumberFormatter : NSNumberFormatter | ||
|
||
/*! | ||
Initialise with WPF style formatter as per https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.110).aspx | ||
*/ | ||
- (id)initWithWPFStyleFormatString:(NSString *)wpfStyleFormatter; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// | ||
// TSPageNumberFormatter.m | ||
// PDFPageBuilder | ||
// | ||
// Created by Jonathan Mitchell on 16/02/2015. | ||
// Copyright (c) 2015 Thesaurus Software. All rights reserved. | ||
// | ||
|
||
#import "TSPageNumberFormatter.h" | ||
|
||
@implementation TSPageNumberFormatter | ||
|
||
#pragma mark - | ||
#pragma mark Lifecycle | ||
|
||
- (id)initWithWPFStyleFormatString:(NSString *)wpfStyleFormatter | ||
{ | ||
self = [super init]; | ||
|
||
// see https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.110).aspx | ||
NSString *formatSpecifier = [[wpfStyleFormatter substringWithRange:NSMakeRange(0, 1)] uppercaseString]; | ||
NSInteger precisionSpecifier = 0; | ||
if (wpfStyleFormatter.length > 1) { | ||
precisionSpecifier = [[wpfStyleFormatter substringWithRange:NSMakeRange(1, wpfStyleFormatter.length - 1)] integerValue]; | ||
} | ||
|
||
// numeric | ||
if ([formatSpecifier isEqualToString:@"N"] || [formatSpecifier isEqualToString:@"F"]) { | ||
|
||
self.numberStyle = NSNumberFormatterDecimalStyle; | ||
[self setHasThousandSeparators:YES]; | ||
|
||
// scientific | ||
} else if ([formatSpecifier isEqualToString:@"E"]) { | ||
|
||
self.numberStyle = kCFNumberFormatterScientificStyle; | ||
|
||
// percent | ||
} else if ([formatSpecifier isEqualToString:@"P"]) { | ||
|
||
self.numberStyle = kCFNumberFormatterPercentStyle; | ||
|
||
// currency | ||
} else if ([formatSpecifier isEqualToString:@"C"]) { | ||
|
||
self.numberStyle = NSNumberFormatterCurrencyStyle; | ||
[self setHasThousandSeparators:YES]; | ||
|
||
} else { | ||
|
||
// other document WPF format specifiers can be implemented as required | ||
self.numberStyle = NSNumberFormatterNoStyle; | ||
} | ||
|
||
[self setMaximumFractionDigits:precisionSpecifier]; | ||
[self setMinimumFractionDigits:precisionSpecifier]; | ||
|
||
return self; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters