문제

I have NSNumber and NSResultFormatter, that converts number into string and displays it on screen.

In scientific form output for large numbers is "1.345e10" and for small numbers is "1.345e-10".

I want to output large numbers as "1.345e+10", like in standart iOS calc app. How can I to do it?

도움이 되었습니까?

해결책

You can achieve that by setting a custom number format, for example:

NSNumberFormatter *fmt = [[NSNumberFormatter alloc] init];
[fmt setExponentSymbol:@"e"];
[fmt setPositiveFormat:@"0.###E+0"];
NSString *s = [fmt stringFromNumber:@(12345678900)];
// 1.235e+10

Custom number formats are documented in http://www.unicode.org/reports/tr35/tr35-25.html#Number_Format_Patterns.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top