-3

I have a values like that: 100, 1220, 10015 basically last 2 digits are cents and I need to convert to dollar (currency) format similar to: 1.00, 12.20, 100.15

Can somebody suggest a quick implementation?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Mike T
  • 53
  • 2
  • 8

1 Answers1

1
var a = 1011
var b = Double(a) / 100
Moris Kramer
  • 1,490
  • 1
  • 12
  • 13
  • Doesn't work for anything like `100, 200` etc. Will only have one decimal. – user3483203 Apr 10 '18 at 20:58
  • @chrisz Of course this will work with 100 and 200. It will work for any number converted from cents to dollars. It's all a matter of how you convert the `Double` to a `String. – rmaddy Apr 10 '18 at 21:14
  • You can then take the number shown above and convert it to a currency formatting string using the answer here: https://stackoverflow.com/a/11787799/3708242 – wottle Apr 10 '18 at 21:21