convert number to words ,in objective c

后端 未结 2 1048
时光取名叫无心
时光取名叫无心 2021-01-18 03:20

I need to write numbers like: 1>yek

123>yeksad o bist o se

1,123>yek hezar o yeksad o bist o se

3,002,001>se milion o do hezar o yek ...

I

相关标签:
2条回答
  • 2021-01-18 03:42

    Swift version of @Vladimir answer (Just in case)

    let formatter = NSNumberFormatter()
    formatter.numberStyle = .SpellOutStyle
    formatter.locale = NSLocale(localeIdentifier: "en_US")
    let string = formatter.stringFromNumber(55015515)
    
    0 讨论(0)
  • 2021-01-18 03:50

    NSNumberFormatter class has built-in functionality for conversion numbers to words:

    NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
    [formatter setNumberStyle: NSNumberFormatterSpellOutStyle];
    [formatter setLocale:...]; // Set locale if you want to use something other then the current one
    NSString* numberString = [formatter stringFromNumber:[NSNumber numberWithInt: 100]];
    
    0 讨论(0)
提交回复
热议问题