Re: NSXMLDocument outputs numbers in exponential format?
Re: NSXMLDocument outputs numbers in exponential format?
- Subject: Re: NSXMLDocument outputs numbers in exponential format?
- From: Fritz Anderson <email@hidden>
- Date: Mon, 1 Mar 2010 14:53:52 -0600
On 1 Mar 2010, at 1:37 PM, Colin Cornaby wrote:
> I'm working with NSXMLDocument and serializing it to a file... The issue is the serialized output contains numbers in exponential formal, i.e. installKBytes="1.744E3". Other programs aren't parsing this correctly... Is there any way to modify the output to just format the numbers normally?
I see this in the documentation for -[NSXMLNode setObjectValue:] (which I assume you're passing an NSNumber into):
======
Note: Prior to Mac OS X v 10.6 setObjectValue: would improperly and inconsistently format objects that were NSNumber instances. Applications linked on Mac OS X 10.6 or later will use correct scientific notation for all NSNumbers passed to setObjectValue:.
If you require a particular format for any value in your XML document, you should format the data yourself as a string and then use setStringValue: to set the value. This guarantees that the text generated is in a format you control directly.
======
So if your consumers don't like scientific notation, use an NSNumberFormatter to get the preferred format, and set the string value yourself.
The same applies, I imagine, to -[NSXMLElement setAttributesAsDictionary:].
Possibly I'm misunderstanding you. You really don't say how you're putting your numbers into the document.
— F
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden