如何在单词中显示印度和欧元区域设置数值?

时间:2016-08-04 12:36:31

标签: ios currency nslocale

我正努力用文字显示印度和欧元区域价值。请任何人帮忙。

$('.date-own').datepicker({
        minViewMode: 1,
        format: 'mm-yyyy'
    });

1 个答案:

答案 0 :(得分:0)

我知道现在已经很晚了。我试过以下解决方案,可能不是最好的解决方案,但它对我有用。希望它会有用。

注意: - 我只考虑过crore scale

@IBAction func startBtnClicked(sender: AnyObject) {

    if var amountStr = ammountTextField.text
    {
        let numberFormater = NSNumberFormatter()

        if amountStr.containsString(",")
        {
            amountStr = amountStr.stringByReplacingOccurrencesOfString(",", withString: "")
        }

        //eg: - amountStr = "45678432"

        if let amountNumber = numberFormater.numberFromString(amountStr)
        {
            //First get currency format
            let currencyFormatter = NSNumberFormatter()
            currencyFormatter.numberStyle = .CurrencyStyle
            currencyFormatter.currencySymbol = ""
            currencyFormatter.locale = NSLocale(localeIdentifier: "en_IN")

            let amountInCurrencyFormatStr = currencyFormatter.stringFromNumber(amountNumber)

            //amountInCurrencyFormatStr = "4,56,78,432"

            var outputStr = ""

            //Get each component in array 

            if let amountInCurrencyFormatComponentArray = amountInCurrencyFormatStr?.componentsSeparatedByString(",")
            {
                //[4,56,78,432]

                let scaleStrArr = ["thousand","lakh","crore"]

                let spellFormatter = NSNumberFormatter()
                spellFormatter.numberStyle = .SpellOutStyle

                var scaleStrCount = 0

                for var i = (amountInCurrencyFormatComponentArray.count - 1) ; i >= 0  ; i--
                {
                    //Iterate array, and append scale strings (["thousand","lakh","crore"]) at proper place

                    if let currencyStr = spellFormatter.stringFromNumber(numberFormater.numberFromString(amountInCurrencyFormatComponentArray[i])!)
                    {
                        if i == (amountInCurrencyFormatComponentArray.count - 1)
                        {
                            outputStr = currencyStr
                        }
                        else
                        {
                            if scaleStrCount < scaleStrArr.count
                            {
                                outputStr = "\(currencyStr) \(scaleStrArr[scaleStrCount]) \(outputStr)"

                                scaleStrCount++
                            }
                            else
                            {
                                outputStr = "\(currencyStr) \(outputStr)"
                            }

                        }
                    }
                    else
                    {
                        print("ERROR: - Unable to spell")
                    }

                }
            }
            else
            {
                print("ERROR: - No , in text field")
            }

            ammountTextField.text = amountInCurrencyFormatStr

            print("OUTPUT --> \(outputStr)")
            //OUTPUT -> "four crore fifty-six lakh seventy-eight thousand four hundred thirty-two"

        }
        else
        {
            print("ERROR: - No Number in text field")
        }


    }
    else
    {
        print("ERROR: - No value in text field")
    }
}