0

我正在制作一个 iOS 计算器应用程序,其中通过使用启用科学概念

Label.text = [NSString stringWithFormat:@"%g",savedValue];

它的格式是例如1.09101e+120。由于我有足够的显示空间,我想让它更合乎逻辑并将其显示为1.09101x10 120
如何做到这一点?

4

3 回答 3

3
于 2012-08-27T12:43:15.390 回答
1

我懒得介绍一个 Objective-C 解决方案,但这里有一个用 Python 完成的灵感:

>>> import re
>>> s = '1.09101e+120'
>>> (mantissa, expsign, exp) = re.match('^(.*)[Ee]([-+]?)(\d+)', s).groups()
>>> super = u''.join( u'⁰¹²³⁴⁵⁶⁷⁸⁹'[int(d)] for d in exp )
>>> print mantissa + u'×10' + ('-' if expsign == '-' else '') + super
1.09101×10¹²⁰
于 2012-08-27T13:05:48.133 回答
0

您可以将CATextLayerNSAttributedString一起使用(iOS 3.2 及更高版本)。

NSDictionary * superScriptAttribute = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:1] forKey:kCTSuperscriptAttributeName];  

查看单个 UILabel 中的粗体和非粗体文本?

于 2012-08-27T13:31:22.637 回答