I'm having problems with
+ (NSDecimalNumber *)decimalNumberWithString:(NSString *)numericString locale:(NSDictionary *)locale
Since I want to provide very high precision values programmatically so that I don't initially have floating point errors, apple gives me the only way to rely on an unstable locale.
Thus, the documentation speaks of a rather encrypted form:
Parameters: ... place of action A dictionary that defines the locale (in particular, NSDecimalSeparator) to use in interpret the number in a number line.
Discussion The locale parameter determines whether the NSDecimalSeparator is a period (as used, for example, in the USA) or a comma (used, for example, in France).
Well, after searching for NSDecimalSeparator, nothing was found in the documents. A network search found that this item is "out of date." So now I am doing something dangerous:
NSLocale *usLoc = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]; NSDecimalNumber *num = [NSDecimalNumber decimalNumberWithString:str locale:usLoc];
So, I wonder: if they really need this warlike locale for something important (I add lines programmatically, without user input), could I somehow create my own language? This parameter wants an NSDictionary, so the idea is:
Can I create an NSMutableDictionary from this language dictionary that appears for -initWithLocaleIdentifier: @ "en_US" and then just edit this%? & §! NSDecimalSeparator field?
And one more thing that raises my headaches: why does the parameter ask for the NSDictionary, where do I need to pass the NSLocale object? Or is my code incorrect? (not tested since my application is currently completely confused ;-))
HelloMoon
source share