0

I have an NSForm that is being used to display content to the user. The form can either be updated via the application by connecting to an web hosted XML file or manually edited by the user. Through Interface Builder I have set each form value to be formatted through an NSNumberFormatter to make the display of the data easier to read. The NSNumberFormatter is only inserting the thousands separator.

Because the data can be manually edited by the user, I am extracting the stringValue of the NSForm fields. I have noticed that when I perform this function, it also grabs the commas that have been injected into the string. I need to do some math with these values and it's causing a problem when trying to call NSString intValue or NSString floatValue. Anyone have any ideas?

I was thinking that I might have to "pre-parse" the string to remove the commas before converting it to a float or int value.

4

1 回答 1

1

NSNumberFormatter也可以向后工作:

NSNumber *n = [formatter numberFromString:@"123,456.78"];
float x = [n floatValue];
于 2013-05-22T21:48:06.103 回答