2016-08-04 4 views
1

저는 인도어와 유로 로케일 값을 단어로 표시하기 위해 고심하고 있습니다. 누구든지이 일을 도와주세요.인디언 및 유로 로케일 번호 값을 단어로 표시하는 방법은 무엇입니까?

var outputString = "" 
    let valueString = "9,58,888.875" 
    let valueFormatter = NSNumberFormatter() 
    let outputFormatter = NSNumberFormatter() 
    outputFormatter.numberStyle = NSNumberFormatterStyle.DecimalStyle 
    valueFormatter.numberStyle = NSNumberFormatterStyle.SpellOutStyle 
    outputString = valueFormatter.stringFromNumber(outputFormatter.numberFromString(valueString as String)!)! 
    print(outputString) 

답변

0

매우 늦었습니다. 나는 다음과 같은 해결책을 시도했지만, 최선의 해결책이 아닐지 모르지만 그것은 나를 위해 일하고있다. 희망이 유용 할 것입니다.

참고 : - I 만 억 루피 규모까지 고려했다

@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") 
    } 
} 
관련 문제