Thursday 15 August 2013

nsnumberformatter - What is the best way to format string representation of number in iOS -


I'm writing in ace app, I've got a Jason object whose value is represented by the string, Some:

  {"price": "20000"}   

And for the ease of readability, I want to format it with command, and I Have found a way, but I think it's a crazy clanky (I probably just did not use the right words in Google)

  NSNumberFormatter * formatter = [NSNumberFormatter new]; [Setter Settlement Style: NSNumberFormatterDecimalStyle]; NSString value = [NSString stringWithFormat: @ "$% @", [formatter stringFromNumber: [NSNumber numberElectrical: [value intValue]]]];   

This is very complicated for me to get the proper formatting

  1. Convert NSSTING to a bowel.
  2. Convert int to nsnm.
  3. Convert NSNM to NSSTING
  4. Create a new string with the appropriate format (@ David / @ van) How do I leave this step!) <

    Best for currency NSNumberFormatterCurrencyStyle NSNumberFormatter * formatter = [NSNumberFormatter new] ; [Setter Settlement Style: NSNumberFormatterCurrencyStyle]; NSNumber * price = @ ([priceTextFromJSON double value]); NSString * priceText = [format stringfarmNumber: value];

No comments:

Post a Comment