What locale argument to pass to NSDecimalNumber +decimalNumberWithString:locale: so it always works with NSString's using the dot (.) decimal mark?

[亡魂溺海] 提交于 2019-12-04 05:08:05
Dave Gallagher

This appears to work well, and is more explicit:

NSDictionary    *l = [NSDictionary dictionaryWithObject:@"." forKey:NSLocaleDecimalSeparator];
NSDecimalNumber *n = [NSDecimalNumber decimalNumberWithString:@"1.234" locale:l];

NSLocaleDecimalSeparator is a constant defined for NSLocale, which responds to -objectWithKey:, just like NSDictionary. You can feed it any decimal mark separator you want, like @",".

I think this is likely the best answer to the question, unless anyone else has a better idea?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!