-2

I have string 99897.05 and I want to convert it like this 99 897.05 example: input: 8121.1 output 8 121.1

input 111111.11 output 111 111.11

  • 1
    Show what you've tried and the output you're getting. – Andrew Mortimer Oct 18 '18 at 09:35
  • Possible duplicate: https://stackoverflow.com/questions/41558832/how-to-format-a-double-into-currency-swift-3 – Scriptable Oct 18 '18 at 09:35
  • Hi there... I think you should really add some of the that you tried to implement for resolving this issue, if you didn't do any effort so far, I'd highly recommend to do so before asking about it; As a hint: `NumberFormatter` might be what are you looking for – Ahmad F Oct 18 '18 at 09:46
  • 1
    Also: you could [*search*](https://stackoverflow.com/search?q=swift+currency) for it before posting your question. – Ahmad F Oct 18 '18 at 09:48

1 Answers1

2

What you need is the currencyGroupingSeparator:

let amount = 99897.05
let formatter = NumberFormatter()
formatter.numberStyle = .currency
formatter.currencyGroupingSeparator = " "

formatter.string(for: amount) //"$99 897.05"

You could change it whatever you'd like:

formatter.currencyGroupingSeparator = ""
formatter.string(for: amount) //"$99897.05"
ielyamani
  • 17,807
  • 10
  • 55
  • 90