Re: Float behaviour
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