Search code examples
iosios9nsdecimalnumberswift2

How to bring NSDecimalNumber from core data to label with 2 digits after , or . even if the value is round


In my CoreData Base is a value 12500.00, it is stored as 12500.

I want to bring it in a tableview label and I would like to have a number with 2 digits like currency.

var unit = "€"    
textLabel.text = ("%@ %.2f" ,unit, (entityName[indexPath.row].price!))`

I do get only the Numbers with decimal like € 12500,55 in my label, but not € 12500,00


Solution

  • let currency = "€"
    let costAsString = String(format: "\(currency) %.2f", Double(12500))
    print(costAsString) // € 12500.00