//
//  DoubleExt.swift
//  ClientManager
//
//  Created by Zachary Gover on 6/7/17.
//  Copyright © 2017 Zachary Gover. All rights reserved.
//

import UIKit

extension Double {

    var to2Decimal: String {
        let formatter = NumberFormatter()
        formatter.minimumFractionDigits = 0
        formatter.maximumFractionDigits = 2
        return formatter.string(from: NSNumber(value: self))!
    }

    var to1Decimal: String {
        let formatter = NumberFormatter()
        formatter.minimumFractionDigits = 0
        formatter.maximumFractionDigits = 1
        return formatter.string(from: NSNumber(value: self))!
    }

    var toCurrency: String {
        let formatter = NumberFormatter()
        formatter.numberStyle = .currency

        if let currency = formatter.string(from: NSNumber(value: self)) {
            return currency
        }

        return formatter.string(from: 0)!
    }

}
