Re: rounding a float
Re: rounding a float
- Subject: Re: rounding a float
- From: Rainer Brockerhoff <email@hidden>
- Date: Mon, 1 Dec 2003 22:55:39 -0200
At 19:48 -0500 01/12/2003, Jay Rimalrick wrote:
>
ok say I wanted to divide 1.23 by 2
>
>
i would really behind the scenes I would take 123/2 which would give me 61.5
>
and which is 61 in integer form ... I lose the .5 which i need it to round up to
>
62.
>
>
I display it as (123/2)/100 which is .61 .... I lose that cent :-(
>
>
please correct my understanding above and let me know if I am still not
>
getting it.
Correct. If you want to round up do: ((123+1)/2)/100. The extra 1 is half of what you're dividing it by (in this case 2).
--
Rainer Brockerhoff <email@hidden>
Belo Horizonte, Brazil
"It's extremely unlucky to be superstitious, for no other reason
than it is always unlucky to be colossally stupid." (Stephen Fry)
Weblog:
http://www.brockerhoff.net/bb/viewtopic.php
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.