That would be an idea. I think my reluctance to do that initially was down 
still not understanding floats and their imprecision. I use bindings for some 
columns directly into the Core Data INT attribute. I presume I can use a Value 
Transformer to do this last tweak of the data?

Also, am I right in thinking that a float's imprecision only occurs when trying 
to use the least significant digit of the float? The one that's rounded up 
because we've ran out of bits? And therefore all the values before that are 
expected to be accurate?

-----Original Message-----
From: Daniel Hyde [mailto:[EMAIL PROTECTED]
Sent: Tuesday, 4 November 2008 9:38 AM
To: HAMILTON, Steven
Subject: Re: FW: NSNumberFormatter: Display INT as decimal

Can you not simply cast to float, divide by your scaling factor, and
display the result at display time?  Then you can just use the normal
float formatting rules to display to 2 decimal places (or however many
you like)

int myAccurateRepresentation = 12789;  // in cents
float myScaleFactor = 100.0;  // number of cents in a dollar
float myDisplayValue = (float)myAccurateRepresentation / myScaleFactor;
// myDisplayValue == 127.89

If you wanted even more accuracy, simply store a finer grain value in
your accurate representation and increase your scale factor
appropriately, eg:

... = 1278900;  // in hundredths-of-cents
... = 10000.0;   // number of hundredths-of-cents in a dollar
... -> 127.89

This e-mail is sent by Suncorp-Metway Limited ABN 66 010 831 722 or one of its 
related entities "Suncorp".
Suncorp may be contacted at Level 18, 36 Wickham Terrace, Brisbane or on 13 11 
55 or at suncorp.com.au.
The content of this e-mail is the view of the sender or stated author and does 
not necessarily reflect the view of Suncorp. The content, including 
attachments, is a confidential communication between Suncorp and the intended 
recipient. If you are not the intended recipient, any use, interference with, 
disclosure or copying of this e-mail, including attachments, is unauthorised 
and expressly prohibited. If you have received this e-mail in error please 
contact the sender immediately and delete the e-mail and any attachments from 
your system.
If this e-mail constitutes a commercial message of a type that you no longer 
wish to receive please reply to this e-mail by typing Unsubscribe in the 
subject line.
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to