DevX Home Today's Headlines   Articles Archive   Tip Bank   Forums

1. Toms Ng Guest

## Deeply Round Up

i want to know that
if i want to round up the 3.1 to 4
i can use ceiling(3.1)
but
if i want to round up a float
for example
if 3.12 , i want it becomes 3.2
if 3.1 , i want it becomes 3.1
if 3.16 , i want it becomes 3.2 (i can use round(3.16 , 1))
but
is any built-in function can do that(change 3.12 to 3.2)
thanks a lot
Toms

2. Vince Teachout Guest

## Re: Deeply Round Up

On 3 Jul 2001 07:50:23 -0700, "Toms Ng" <Toms@Magic.com> wrote:

>if i want to round up a float
>for example
>if 3.12 , i want it becomes 3.2
>if 3.1 , i want it becomes 3.1
>if 3.16 , i want it becomes 3.2 (i can use round(3.16 , 1))
>but
>is any built-in function can do that(change 3.12 to 3.2)

This is interesting. What are you trying to do? Round anything above .1 up to
the next number, but anything .1 or below down? You can do by adding 0.04 when
rounding - like this:

x = 3.1
? round(x + 0.04, 1) && Prints 3.1

x = 3.12
? round(x + 0.04, 1) && Prints 3.2

x = 3.09
? round(x + 0.04, 1) && Prints 3.1

Not that it's any of my business, but why would you need that? Just curious.

caracal A T caracal D O T net

3. Robert Hoogstraat Guest

## Re: Deeply Round Up

Toms,

There is no native VFP function that does what you want.
However, have you considered using the following code proxy
( CEILING( nExpression * 10^nDecimalPlaces ) / 10^nDecimalPlaces )
where nExpression is your value you want 'rounded', and nDecimalPlaces is
the number of decimal places.
( CEILING( 3.16 * 10^1 ) / 10^1 )
will result in 3.2.
For multiple reuse, the inline code snippet can be converted to a function
and included in a procedure/class library.
--
Robert Hoogstraat [SI]

"Toms Ng" <Toms@Magic.com> wrote in message news:3b41dbaf\$1@news.devx.com...
>
> i want to know that
> if i want to round up the 3.1 to 4
> i can use ceiling(3.1)
> but
> if i want to round up a float
> for example
> if 3.12 , i want it becomes 3.2
> if 3.1 , i want it becomes 3.1
> if 3.16 , i want it becomes 3.2 (i can use round(3.16 , 1))
> but
> is any built-in function can do that(change 3.12 to 3.2)
> thanks a lot
> Toms
>

4. Fred Taylor Guest

## Re: Deeply Round Up

Close, Vince. You need to add .05 (1/2 the unit you're rounding to).

--
Fred
Microsoft Visual FoxPro MVP
Please respond only to the newsgroups so that all may benefit.

"Vince Teachout" <SendJunkMailTo@hotmail.com> wrote in message
news:9qn3kt07nd6c6scrlnobl5kjc38it8poms@4ax.com...
> On 3 Jul 2001 07:50:23 -0700, "Toms Ng" <Toms@Magic.com> wrote:
>
> >if i want to round up a float
> >for example
> >if 3.12 , i want it becomes 3.2
> >if 3.1 , i want it becomes 3.1
> >if 3.16 , i want it becomes 3.2 (i can use round(3.16 , 1))
> >but
> >is any built-in function can do that(change 3.12 to 3.2)

>
> This is interesting. What are you trying to do? Round anything above .1

up to
> the next number, but anything .1 or below down? You can do by adding 0.04

when
> rounding - like this:
>
> x = 3.1
> ? round(x + 0.04, 1) && Prints 3.1
>
> x = 3.12
> ? round(x + 0.04, 1) && Prints 3.2
>
> x = 3.09
> ? round(x + 0.04, 1) && Prints 3.1
>
> Not that it's any of my business, but why would you need that? Just

curious.
>
> Ignore munged e-mail address above.
> caracal A T caracal D O T net

5. Vince Teachout Guest

## Re: Deeply Round Up

On Tue, 3 Jul 2001 20:19:21 -0700, "Fred Taylor" <ftaylor@mvps.org> wrote:

>Close, Vince. You need to add .05 (1/2 the unit you're rounding to).

Negatory, good buddy. I almost did that at first, then I re-read his
requirements:
3.1 must go to 3.1 3.1X must go up to 3.2
0.5 doesn't do that - it will send 3.1 up to 3.2 as well. Try it.
:-)

caracal A T caracal D O T net

6. Vince Teachout Guest

## Re: Deeply Round Up

On Wed, 04 Jul 2001 08:58:18 -0400, Vince Teachout <SendJunkMailTo@hotmail.com>
wrote:

>Negatory, good buddy. I almost did that at first, then I re-read his
>requirements:
>3.1 must go to 3.1 3.1X must go up to 3.2
>0.5 doesn't do that - it will send 3.1 up to 3.2 as well. Try it.

Which, by the way, was why I found the request so intriguing. I can't imagine
why he would need 3.1 to go to 3.1 and 3.1X to go to 3.2

caracal A T caracal D O T net

7. Fred Taylor Guest

## Re: Deeply Round Up

Ah, good point Vince. I missed that subtle detail.

--
Fred
Microsoft Visual FoxPro MVP
Please respond only to the newsgroups so that all may benefit.

"Vince Teachout" <SendJunkMailTo@hotmail.com> wrote in message
news:su46ktg7hfjl2m76pm59mp29nmbqnmdsk6@4ax.com...
> On Wed, 04 Jul 2001 08:58:18 -0400, Vince Teachout

<SendJunkMailTo@hotmail.com>
> wrote:
>
> >Negatory, good buddy. I almost did that at first, then I re-read his
> >requirements:
> >3.1 must go to 3.1 3.1X must go up to 3.2
> >0.5 doesn't do that - it will send 3.1 up to 3.2 as well. Try it.

>
> Which, by the way, was why I found the request so intriguing. I can't

imagine
> why he would need 3.1 to go to 3.1 and 3.1X to go to 3.2
>
> Ignore munged e-mail address above.
> caracal A T caracal D O T net

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 FAQ Latest Articles Java .NET XML Database Enterprise