Swift-NumberFormatter的简单使用

let formatter = NumberFormatter()
 formatter.numberStyle = .spellOut

let a= 10

let aWords = formatter.string(from: a)

print(aWords)//["十"]


public enum Style : UInt {


        case none

        case decimal

        case currency

        case percent

        case scientific

        case spellOut

        @available(iOS 9.0, *)

        case ordinal

        @available(iOS 9.0, *)

        case currencyISOCode

        @available(iOS 9.0, *)

        case currencyPlural

        @available(iOS 9.0, *)

        case currencyAccounting

    }

/*

       例如:1234.568打印结果:

       none = 1235

       decimal = 1,234.568

       currency = $1,234.57

       percent = 123,457%

       scientific = 1.2345678E3

       spellOut = one thousand two hundred thirty-four point five six seven eight //根据手机设置的语言类型变化

       ordinal = 1,235th

       currencyISOCode = USD1,234.57

      currencyPlural = 1,234.57 US dollars

       currencyAccounting = $1,234.57

       */ 

你可能感兴趣的:(Swift-NumberFormatter的简单使用)