0

I have a math solution that I want to show as something like "3.456 * 10^9", but I don't want the ^ symbol, I want the real deal. I have the power-number (9) separate, and they are all in strings. I can turn them into Integers, but I don't know if String can show that type of math. I am using Swift/iOS now, but this is a general question to all development really, no matter what language. What's the 'proper' way of showing this?

Should I store all 'power'-numbers' ascii-values 0-9 and print them out - loop over my power-string and match, or is there a simpler way?

Sti
  • 8,275
  • 9
  • 62
  • 124
  • 2
    In terms of displaying the text, have a look at `NSAttributedString` (https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSAttributedString_Class/). There's also a couple of SO questions on how to display superscript, take a look at http://stackoverflow.com/questions/21415963/nsattributedstring-superscript-styling and http://stackoverflow.com/questions/24300066/how-to-display-superscript-character-as-string-in-uilabel?lq=1. They're obj-c, but you should get the general idea. – Hamish Jan 24 '16 at 21:17
  • A NSString is just characters. Are you looking for showing it in a `UILabel/UITextView`? If yes, you can use `NSAttributedString` (and `NSBaselineAttributeName`). – Larme Jan 24 '16 at 21:17
  • 6
    See [this Q&A](http://stackoverflow.com/questions/29225779/how-to-use-subscript-and-superscript-in-swift) for how to display a superscript in Swift. – Marc Khadpe Jan 24 '16 at 21:17
  • Thank you! As a foreigner, never heard the word superscript before, solved everything! – Sti Jan 26 '16 at 04:56

0 Answers0