• 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
Re: inconsistent float behaviour
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: inconsistent float behaviour


  • Subject: Re: inconsistent float behaviour
  • From: "Clark Cox" <email@hidden>
  • Date: Fri, 10 Oct 2008 19:23:40 -0700

On Fri, Oct 10, 2008 at 6:33 PM, Steven Hamilton <email@hidden> wrote:
> Thanks guys,
> I'm still unsure why I'm getting 4 decimal places as I know for fact that
> the data is 2 decimal places.

That is because floating point numbers don't have "decimal places";
forget all about decimal places. Please read this:
<http://docs.sun.com/source/806-3568/ncg_goldberg.html>, it is, as the
title says: what every computer scientist should know about
floating-point arithmetic.

> However, it seems my approach is wrong. I'll
> convert to int's and NSDecimalNumbers instead and remove all floats.
>
> On 11/10/2008, at 4:14 AM, Uli Kusterer wrote:
>
>> On 10.10.2008, at 13:04, Steven Hamilton wrote:
>>>
>>> NSLog(@"current balance is: %@",balance);
>>>
>>> and get
>>>
>>> current balance is: 18976.69
>>>
>>> in the console. So far so good.
>>>
>>> (...) The float calculation is exactly 2 decimal places, I know that for
>>> a fact and NSLog proves it.
>>
>> You may want to be aware that NSLog gives no guarantees as to the output
>> of its formats if you use %@. All it does is call the -description method of
>> the requisite object. -description is only intended for debugging, and as
>> such what it returns for a particular object may change from release to
>> release, or even from instance to instance (e.g. when you log an NSArray,
>> you occasionally get more detailed output than when logging a
>> toll-free-bridged CFArrayRef).
>>
>> Cheers,
>> -- Uli Kusterer
>> "The Witnesses of TeachText are everywhere..."
>> http://www.zathras.de
>>
>>
>>
>>
>>
>
> _______________________________________________
>
> 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
>



--
Clark S. Cox III
email@hidden
_______________________________________________

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

References: 
 >inconsistent float behaviour (From: Steven Hamilton <email@hidden>)
 >Re: inconsistent float behaviour (From: Uli Kusterer <email@hidden>)
 >Re: inconsistent float behaviour (From: Steven Hamilton <email@hidden>)

  • Prev by Date: Re: inconsistent float behaviour
  • Next by Date: Re: NSNull and @""
  • Previous by thread: Re: inconsistent float behaviour
  • Next by thread: Re: inconsistent float behaviour
  • Index(es):
    • Date
    • Thread