I want converting int number in to letter of this number .I Have one text field .in this text field user can write number then i want convertin this number to letter . for example i want convert 11 to eleven .how can i do this work in swift .
Asked
Active
Viewed 665 times
3
-
2Hi Hadiseh, welcome to the site. Read the documentation of [`NumberFormatter`](https://developer.apple.com/documentation/foundation/numberformatter), it does what you're looking for, with `numberStyle` set to `.spellOut` – Alexander Dec 19 '19 at 15:13
-
the opposite direction https://stackoverflow.com/a/46856525/2303865 – Leo Dabus Dec 19 '19 at 16:29
1 Answers
8
You can use like this :
let formatter = NumberFormatter()
formatter.numberStyle = .spellOut
let english = formatter.string(from: 1)
and you can Refer this Awesome Answer for objective-c.
If you wanted to get that in Espanol , you would set a locale like this:
formatter.locale = Locale(identifier: "es_ES")
let spanish = formatter.string(from:1)

Dhaval Raval
- 594
- 2
- 7
-
2It won't be `English` unless implicit current `Locale` is `en_*`. So calling variable `english` is misleading. – user28434'mstep Dec 19 '19 at 15:25
-
Hi You can use your local, for example spanish like this : formatter.locale = Locale(identifier: "es_ES") let spanish = formatter.string(from: 1) – Dhaval Raval Dec 19 '19 at 15:27
-
You have to change identifier for your local language , as i have edited the answer for example. – Dhaval Raval Dec 19 '19 at 15:32