• 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: A Newbie Float Problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A Newbie Float Problem


  • Subject: Re: A Newbie Float Problem
  • From: Shawn Erickson <email@hidden>
  • Date: Fri, 16 Dec 2005 09:38:54 -0800

On 12/15/05, Jonathan Faulkenberry <email@hidden> wrote:
> Hi all,
> I am relatively new to Cocoa, although I have some experience with
> some basic C. For some reason though, I am having trouble creating a
> small app I am using to help me learn Cocoa. This app is supposed to
> hold a float value named "money" an have two buttons, one which will
> call addMoney: (which will add 5 to the float value) and one called
> drink: (which will decrease the float value by 5). For some reason,
> when I click on the button that calls addMoney:, the value of the
> float goes to like a 10 digit number.

Others pointed out the incorrect format statement you are using.

To get a better understand of printf style formats review man 3 printf
or visit the following...
<http://developer.apple.com/documentation/Darwin/Reference/ManPages/man3/printf.3.html>
<http://developer.apple.com/documentation/Cocoa/Conceptual/DataFormatting/Articles/FormatStrings.html>

...with that said using floats for money calculations (etc.) can
result in unexpected precision errors that could confuse you and/or
customers. The following is from a Java perspective but I found it to
be the easiest document that covers the issue I am attempting to point
out to you...

<http://java.sun.com/developer/JDCTechTips/2001/tt0807.html#tip1>

After reading the above consider NSDecimal (akin to BigDecimal in Java)...

<http://developer.apple.com/documentation/Cocoa/Conceptual/NumbersandValues/index.html#//apple_ref/doc/uid/10000038i>
<http://developer.apple.com/documentation/Cocoa/Reference/Foundation/ObjC_classic/Classes/NSDecimalNumber_index.html>

-Shawn
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >A Newbie Float Problem (From: Jonathan Faulkenberry <email@hidden>)

  • Prev by Date: Re: Warnings with NSError **
  • Next by Date: Whre find safari style tabs in IB
  • Previous by thread: Re: A Newbie Float Problem
  • Next by thread: How To retrieve the Relationsships from an entity in Core Data
  • Index(es):
    • Date
    • Thread