Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As you already noticed, NSNumberFormatter converts to float. Sadly there's only descriptionWithLocale as an alternative, which doesn't provide a way change the behaviour you want. The best way should be to write you own formatter, Apple even provides a guide for that:</p> <p><a href="https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/DataFormatting/DataFormatting.html" rel="nofollow">https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/DataFormatting/DataFormatting.html</a></p> <p>I would take the descriptionWithLocale as a starting point and look for the separator. Then add comas every 3 digits before it.</p> <p>Edit:</p> <p>Another idea would be to split the string in the integer part and the stuff behind the separator, then format the integer part using the formatter and combine it with the rest after that.</p> <pre><code>// Get the number from the substring before the seperator NSString *output = [number descriptionWithLocale:nil]; NSNumber *integerPartOnly = [NSNumber numberWithInt:[output intValue]]; // Format with decimal separators NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; [formatter setFormatterBehavior:NSNumberFormatterBehavior10_4]; [formatter setNumberStyle:kCFNumberFormatterDecimalStyle]; NSString *result = [formatter stringFromNumber:integerPartOnly] // Get the original stuff from behind the separator NSArray* components = [output componentsSeparatedByString:@"."]; NSString *stuffBehindDot = ([components count] == 2) ? [components objectAtIndex: 1] : @""; // Combine the 2 parts NSString *result = [result stringByAppendingString:stuffBehindDot]; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload