Is there a simple calculation that will always Round Up to the next whole
number.
Such that 7 divided by 3 results in 3 rather than the normal rounded result
of 2.
Object is a calculation that derives material to purchase but answer must
always be a complete unit even if only 2 tenths of a unit is required.
John G.
|
|
0
|
|
|
|
Reply
|
green1979 (15)
|
8/5/2008 8:59:24 AM |
|
In article
<4898165f$0$24178$5a62ac22@per-qv1-newsreader-01.iinet.net.au>,
"John G" <green@ozemail.com.au> wrote:
> Is there a simple calculation that will always Round Up to the next whole
> number.
If(num > Int(num), Int(num) + 1, num)
--
"Harry?" Ron's voice was a mere whisper. "Do you smell something ... burning?"
- Harry Potter and the Odor of the Phoenix
|
|
0
|
|
|
|
Reply
|
uce3 (3718)
|
8/5/2008 11:11:14 AM
|
|
On Tue, 05 Aug 2008 07:11:14 -0400, Gregory Weston wrote:
> In article
> <4898165f$0$24178$5a62ac22@per-qv1-newsreader-01.iinet.net.au>,
> "John G" <green@ozemail.com.au> wrote:
>
> > Is there a simple calculation that will always Round Up to the next whole
> > number.
>
> If(num > Int(num), Int(num) + 1, num)
Does this work for negative numbers?
- 5.5 -> is int(num) then -6 (would compute ok as -5) or -5 (which would
return -5.5)
How about
int(num) + if(num ≠ int(num), 1)
.... looks ok for a first glance but might return -4 instead :-(
|
|
0
|
|
|
|
Reply
|
t-use (417)
|
8/5/2008 11:28:30 AM
|
|
"Gregory Weston" <uce@splook.com> wrote in message
news:uce-F9B5A1.07111405082008@newsclstr03.news.prodigy.net...
> In article
> <4898165f$0$24178$5a62ac22@per-qv1-newsreader-01.iinet.net.au>,
> "John G" <green@ozemail.com.au> wrote:
>
>> Is there a simple calculation that will always Round Up to the next whole
>> number.
>
> If(num > Int(num), Int(num) + 1, num)
>
> --
> "Harry?" Ron's voice was a mere whisper. "Do you smell something ...
> burning?"
> - Harry Potter and the Odor of the Phoenix
Thanks,
I should think more but Math 101 was back in the fifties.
John G.
|
|
0
|
|
|
|
Reply
|
green1979 (15)
|
8/5/2008 11:32:03 AM
|
|
On Aug 5, 2:59 am, "John G" <gr...@ozemail.com.au> wrote:
> Is there a simple calculation that will always Round Up to the next whole
> number.
>
> Such that 7 divided by 3 results in 3 rather than the normal rounded result
> of 2.
>
> Object is a calculation that derives material to purchase but answer must
> always be a complete unit even if only 2 tenths of a unit is required.
>
> John G.
The function you're looking for is named: Ceiling()
G
|
|
0
|
|
|
|
Reply
|
grip (545)
|
8/5/2008 2:13:52 PM
|
|
In article <slrng9geau.l8i.t-use@ID-685.user.individual.de>,
Martin Trautmann <t-use@gmx.net> wrote:
> On Tue, 05 Aug 2008 07:11:14 -0400, Gregory Weston wrote:
> > In article
> > <4898165f$0$24178$5a62ac22@per-qv1-newsreader-01.iinet.net.au>,
> > "John G" <green@ozemail.com.au> wrote:
> >
> > > Is there a simple calculation that will always Round Up to the next whole
> > > number.
> >
> > If(num > Int(num), Int(num) + 1, num)
>
> Does this work for negative numbers?
A fair question. My use of > means that it won't work with negative
numbers. A bit of a deviation from the original post since the OP was
looking to round up quantities of ordered materials. Anything less than
zero would be anomalous, I'd think.
> - 5.5 -> is int(num) then -6 (would compute ok as -5) or -5 (which would
> return -5.5)
>
> How about
> int(num) + if(num ≠ int(num), 1)
> ... looks ok for a first glance but might return -4 instead :-(
My biggest issue with this is that equality tests with some numeric
representations can be a bit fidgety. I have no idea what FMP uses
internally to store numbers so I went with a solution that's reliable in
general given the reasonable-to-me assumption that the input will always
be >= 0.
--
"Harry?" Ron's voice was a mere whisper. "Do you smell something ... burning?"
- Harry Potter and the Odor of the Phoenix
|
|
0
|
|
|
|
Reply
|
uce3 (3718)
|
8/5/2008 4:46:01 PM
|
|
"Grip" <grip@cybermesa.com> wrote in message
news:9efc7dc2-df74-44b2-8ad6-ee65121fe262@m44g2000hsc.googlegroups.com...
> On Aug 5, 2:59 am, "John G" <gr...@ozemail.com.au> wrote:
>> Is there a simple calculation that will always Round Up to the next whole
>> number.
>>
>> Such that 7 divided by 3 results in 3 rather than the normal rounded
>> result
>> of 2.
>>
>> Object is a calculation that derives material to purchase but answer must
>> always be a complete unit even if only 2 tenths of a unit is required.
>>
>> John G.
>
> The function you're looking for is named: Ceiling()
>
> G
Thanks for that. I would never have guessed Ceiling() was just the function
I needed and of course I would have to take care of the way it only Rounds
UP, ie negative numbers get smaller.
I must study the Help file more in my Spare? time.
John G.
|
|
0
|
|
|
|
Reply
|
green1979 (15)
|
8/5/2008 11:30:35 PM
|
|
"Martin Trautmann" <t-use@gmx.net> wrote in message
news:slrng9geau.l8i.t-use@ID-685.user.individual.de...
> On Tue, 05 Aug 2008 07:11:14 -0400, Gregory Weston wrote:
>> In article
>> <4898165f$0$24178$5a62ac22@per-qv1-newsreader-01.iinet.net.au>,
>> "John G" <green@ozemail.com.au> wrote:
>>
>> > Is there a simple calculation that will always Round Up to the next
>> > whole
>> > number.
>>
>> If(num > Int(num), Int(num) + 1, num)
>
> Does this work for negative numbers?
>
> - 5.5 -> is int(num) then -6 (would compute ok as -5) or -5 (which would
> return -5.5)
>
>
> How about
> int(num) + if(num ? int(num), 1)
> ... looks ok for a first glance but might return -4 instead :-(
>
Because it is always a negative numer I changed the Greater than to Less
than and changed the Pplus1 to Minus one and it all worked just as desired.
Then put a minus in front of the lot so when the resulting order was printed
it was just a posative number to order.
There are Rounds and Case statements etc and I think it is now the longest
calculation I have ever attempted in FMP
-If(Case(Round (Total110/2000;1)<0;(Round (Total110/2000;1));"") <
Int(Case(Round (Total110/2000;1)<0;(Round
(Total110/2000;1));""));Int(Case(Round (Total110/2000;1)<0;(Round
(Total110/2000;1));"")) - 1;Case(Round (Total110/2000;1)<0;(Round
(Total110/2000;1));""))
All the fields are Globals that I did not name very well sorry.
This is a great use of News Groups in a world where one may never actually
speak to someone who understands the question.
Thanks again to all for the help.
John G.
|
|
0
|
|
|
|
Reply
|
green1979 (15)
|
8/5/2008 11:43:34 PM
|
|
> Thanks for that. I would never have guessed Ceiling() was just the function
> I needed
Ceiling and Floor are the standard mathematical names for those
functions, and are available in most programming environments under
those names. For more info:
http://en.wikipedia.org/wiki/Ceiling_function
> and of course I would have to take care of the way it only Rounds
> UP, ie negative numbers get smaller.
Ceiling always rounds 'up'
Floor always rounds 'down'.
If, on the other hand, you want a function that always rounds 'away
from zero' then:
sign(n) * ceiling(abs(n))
And for completeness, if you want a function that always rounds
'towards' zero, than:
int(n)
-cheers,
Dave
|
|
0
|
|
|
|
Reply
|
db.porsche (396)
|
8/6/2008 12:10:07 AM
|
|
"Martin Trautmann" <t-use@gmx.net> wrote in message
news:slrng9geau.l8i.t-use@ID-685.user.individual.de...
> On Tue, 05 Aug 2008 07:11:14 -0400, Gregory Weston wrote:
> > In article
> > <4898165f$0$24178$5a62ac22@per-qv1-newsreader-01.iinet.net.au>,
> > "John G" <green@ozemail.com.au> wrote:
> >
> > > Is there a simple calculation that will always Round Up to the next
> > > whole
> > > number.
> >
> > If(num > Int(num), Int(num) + 1, num)
>
> Does this work for negative numbers?
>
> - 5.5 -> is int(num) then -6 (would compute ok as -5) or -5 (which would
> return -5.5)
>
>
> How about
> int(num) + if(num ? int(num), 1)
> ... looks ok for a first glance but might return -4 instead :-(
If you want numbers to round up with negative getting closer to 0, then
I think this this one works:
Round(NumField + 0.4, 0)
This means -5.2 rounds up to -5
But, if you want negative numbers to round down (further from 0), then
I think this one works instead:
Sign(NumField) * Round(Abs(NumField) + 0.4, 0)
With this one, -5.2 will be rounded to -6.
In both cases 0 is still rounded to 0.
Helpful Harry
Hopefully helping harassed humans happily handle handiwork hardships ;o)
|
|
0
|
|
|
|
Reply
|
helpful_harry (1511)
|
8/6/2008 12:57:24 AM
|
|
On Wed, 06 Aug 2008 12:57:24 +1200, Helpful Harry wrote:
> If you want numbers to round up with negative getting closer to 0, then
> I think this this one works:
>
> Round(NumField + 0.4, 0)
>
> This means -5.2 rounds up to -5
How about 5.01? You'd have to use
0.499999999999999999999999999999999999999999999999 instead...
(which might fail not only for even more decimal digits, but my fail due
to an internal rounding up to 0.5 as well - and will assume 0.5 for very
high numbers).
> Sign(NumField) * Round(Abs(NumField) + 0.4, 0)
Sign is a trivial solution - I'd like a more elegant one :-)
- Martin
|
|
0
|
|
|
|
Reply
|
t-use (417)
|
8/6/2008 8:34:36 AM
|
|
On Aug 6, 1:34=A0am, Martin Trautmann <t-...@gmx.net> wrote:
> On Wed, 06 Aug 2008 12:57:24 +1200, Helpful Harry wrote:
> > =A0If you want numbers to round up with negative getting closer to 0, t=
hen
> > =A0I think this this one works:
>
> > =A0 =A0 Round(NumField + 0.4, 0)
>
> > =A0This means -5.2 rounds up to -5
>
> How about 5.01? You'd have to use
> 0.499999999999999999999999999999999999999999999999 instead...
>
> (which might fail not only for even more decimal digits, but my fail due
> to an internal rounding up to 0.5 as well - and will assume 0.5 for very
> high numbers).
>
> > =A0 =A0 =A0 Sign(NumField) * Round(Abs(NumField) + 0.4, 0)
>
> Sign is a trivial solution - =A0I'd like a more elegant one :-)
>
> - Martin
As I wrote elsewhere in this thread:
If you want a function that always rounds 'away
from zero' then:
sign(n) * ceiling(abs(n))
If you want a function that always rounds
'towards' zero, than:
int(n)
-regards,
Dave
|
|
0
|
|
|
|
Reply
|
db.porsche (396)
|
8/6/2008 5:57:58 PM
|
|
|
11 Replies
37 Views
(page loaded in 0.155 seconds)
|