1

Please guide me an issue, I am getting a price from the server as below (as an example)

two hundred forty-two

and I want to convert this value into 242.00.

Please guide me on how to convert it.

I know we can use .spellOut with NumberFormatter for converting value into String but can't find a way to do the above.

4
  • NumberFormatter has a method number(from: String)? It doesn't work? Else, I wonder if there is a (NS)DataDetector that might work on that. Commented Dec 25, 2021 at 17:34
  • @Larme Thanks, tried but didn’t work. Commented Dec 25, 2021 at 17:40
  • 1
    ask your backend to change the text for number. Commented Dec 25, 2021 at 17:57
  • This is really a server problem. Are you sure that the server intends for your to parse this string into a real number? Perhaps it is only intended to be displayed as text to the user and not actually converted to decimal. If not, then it's really the responsibility of the server to change this. Commented Dec 25, 2021 at 18:01

1 Answer 1

1

Alright, you have managed to nerd-snipe me.

I've implemented a number string parser as a Swift package. I don't expect you to bring in a whole package just to do this, but you might find some inspiration here:

https://github.com/daltonclaybrook/NumberParser

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.