• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Number formatting
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Number formatting


  • Subject: Number formatting
  • From: John MacMullin <email@hidden>
  • Date: Tue, 7 Oct 2003 21:30:19 -0700

Charles Srstka posted the following, also on mamasam, regarding a
workaround with respect to number formatting.

NSNumberFormatter *nf = [[[NSNumberFormatter alloc] init] autorelease];

[nf setLocalizesFormat:YES];
nf = [NSUnarchiver unarchiveObjectWithData:
[NSArchiver archivedDataWithRootObject:nf]];
[nf setFormat:@"0"];
[nf setHasThousandSeparators:YES];

[sizeField setStringValue:[NSString stringWithFormat:@"%@ (%@ %@)",
[item stringRepresentationOfSize],
[nf stringForObjectValue:[NSNumber numberWithUnsignedLong:[item
sizeInBytes]]],
NSLocalizedString(@"bytes",@"")]];

I followed this example writing the following code: (I am just trying
to format a float number to a currency)

NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc] init]
autorelease];
[numberFormatter setLocalizesFormat:YES];
numberFormatter = [NSUnarchiver unarchiveObjectWithData: [NSArchiver
archivedDataWithRootObject:numberFormatter]];
[numberFormatter setFormat:@"$#,##0.00"];
[numberFormatter stringForObjectValue:[[[self
testFile]objectAtIndex:i]objectAtIndex:fieldFourNumberDef]];
fileFieldFourNumber = [fileFieldFourNumber
stringByAppendingString:[NSString stringWithFormat:@"%@",
numberFormatter]];

When I compile however I get the following message: MyDocument.m:639:
error: stray '\312' in program

Project Builder refers me to the third line above.

Any suggestions on fixing this error?

John
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Number formatting
      • From: Nick Zitzmann <email@hidden>
  • Prev by Date: Re: file sizes from NSFileManager
  • Next by Date: Re: Detecting keyDown in a NSTextField?
  • Previous by thread: Re: actions across nibs
  • Next by thread: Re: Number formatting
  • Index(es):
    • Date
    • Thread