How to convert number to text like spoken language?

前端 未结 1 856
没有蜡笔的小新
没有蜡笔的小新 2021-01-25 11:38

If value is in million then the string should be .. miliion ..thousand ..hundred. I used this code but it showing million value in thousand, how to resolve this iss

相关标签:
1条回答
  • 2021-01-25 12:06

    It works for me.

    Code:

    #import <Foundation/Foundation.h>
    
    int main(int argc, char *argv[]) {
        @autoreleasepool {
                 //convert to words
                 NSString *wordNumber;
                 NSNumber *numberValue = @6453323; //needs to be NSNumber!
                 NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
                 [numberFormatter setNumberStyle:NSNumberFormatterSpellOutStyle];
                  //    [numberFormatter setNumberStyle:@"en_IN"];
                 [numberFormatter setLocale:[NSLocale currentLocale]]; // happen by default?
                 wordNumber = [numberFormatter stringFromNumber:numberValue];
                 NSLog(@"Answer: %@", wordNumber);
        }
    }
    

    Output:

    2014-06-11 09:51:35.472 Untitled[480:507] Answer: six million four hundred fifty-three thousand three hundred twenty-three

    0 讨论(0)
提交回复
热议问题