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

Re: Float behaviour


  • Subject: Re: Float behaviour
  • From: Julian <email@hidden>
  • Date: Mon, 22 Aug 2005 15:37:42 -0300

Hi Richard!

In the Currency Converter you will expect at most 2 decimals. Then,
you can correct this behavior, when the value is shown, using
printf-like string format:

Replace in your code the line:

[totalField setFloatValue:total];

by this:

[totalField setStringValue:[NSString stringWithFormat:@"%.2", total]];

With this replacement, your program will show a float number with 2
decimals in the totalField.

You can learn more on string format reading the "printf C-funtion
manual" (type "man printf" on a Terminal).

Happy Programming!

Julian

--
A QuBoy can't clone himself, but he can teleport his mind anywhere!



On 8/22/05, Richard Gray <email@hidden> wrote:
> My apologies for posting to the wrong list then, and my thanks for the
> quick response.  I should have known... It's been a while since I've
> done any programming.
>
> thanks again,
> Richard
>
> > Of course, this has nothing to do with Cocoa, but with floating-point
> > arithmetic.
> >
> > <http://docs.sun.com/source/806-3568/ncg_goldberg.html>
> > "What Every Computer Scientist Should Know About Floating-Point
> > Arithmetic"
> >
> > Jim H
>  _______________________________________________
> 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
>
 _______________________________________________
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: 
 >Float behaviour (From: Richard Gray <email@hidden>)
 >Re: Float behaviour (From: Jim Hamilton <email@hidden>)
 >Re: Float behaviour (From: Richard Gray <email@hidden>)

  • Prev by Date: Re: Accessing an Instance
  • Next by Date: Re: Finding count of a character in a string
  • Previous by thread: Re: Float behaviour
  • Next by thread: Re: Float behaviour
  • Index(es):
    • Date
    • Thread