# Rounding Up - ASP

Is there a way to make your numbers always round up. Ex: if the number is 0.0341 it will round to 0.035 Brent...

1. ## Rounding Up

Is there a way to make your numbers always round up. Ex:
if the number is 0.0341 it will round to 0.035

Brent
Brent Bortnick Guest

2. ## Re: Rounding Up

If you always want it at the thousandths, you could say:

<%
function roundUp(n)
if clng(n*10000) = 10 * clng(n*1000) then
n = formatnumber(n, 3)
else
n = formatnumber(n + 0.0005, 3)
end if
roundup = n
end function

response.write "<br>" & roundUp(0.0341)
response.write "<br>" & roundUp(0.03409)
response.write "<br>" & roundUp(0.0340)
response.write "<br>" & roundUp(0.0359)

%>

"Brent Bortnick" <brenthitechseals.com> wrote in message
news:47db01c340db\$5ae0e710\$a401280aphx.gbl...
> Is there a way to make your numbers always round up. Ex:
> if the number is 0.0341 it will round to 0.035
>
> Brent

Aaron Bertrand - MVP Guest

3. ## Re: Rounding Up

"Brent Bortnick" wrote:
>
> Is there a way to make your numbers always round up. Ex:
> if the number is 0.0341 it will round to 0.035
JScript:
val = Math.ceil(1000*val)/1000
[url]http://msdn.microsoft.com/library/en-us/script56/html/js56jsmthceil.asp[/url]

VBScript (depends on how you want to handle negative numbers):
If val*1000 <> Fix(val*1000) Then val = Fix(val*1000+1)/1000
If val*1000 <> Int(val*1000) Then val = Int(val*1000+1)/1000
[url]http://msdn.microsoft.com/library/en-us/script56/html/vsfctint.asp[/url]

Of course, both methods introduce you to the problem of representing
decimals with binary digits. See this for details:
[url]http://support.microsoft.com/default.aspx?scid=kb;EN-US;q244699[/url]

You can opt for string representations of those numbers with either of the
following.

JScript:
[url]http://msdn.microsoft.com/library/en-us/script56/html/js56jsmthtofixed.asp[/url]

VBScript:
[url]http://msdn.microsoft.com/library/en-us/script56/html/vsfctFormatNumber.asp[/url]

--
Dave Anderson

Unsolicited commercial email will be read at a cost of \$500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.

Dave Anderson Guest

4. ## Re: Rounding Up

Aaron Bertrand - MVP wrote on 02 jul 2003 in
microsoft.public.inetserver.asp.general:
> If you always want it at the thousandths, you could say:
>
> <%
> function roundUp(n)
> if clng(n*10000) = 10 * clng(n*1000) then
> n = formatnumber(n, 3)
> else
> n = formatnumber(n + 0.0005, 3)
> end if
> roundup = n
> end function
>
> response.write "<br>" & roundUp(0.0341)
> response.write "<br>" & roundUp(0.03409)
> response.write "<br>" & roundUp(0.0340)
> response.write "<br>" & roundUp(0.0359)
>
> %>
>
Or:

function roundUp(n)
n = int(n*1000+0.999999)/1000
roundup = formatnumber(n, 3)
end function

--
Evertjan.
The Netherlands.
Evertjan. Guest

5. ## Re: Rounding Up

"Aaron Bertrand - MVP" wrote:
>
> if clng(n*10000) = 10 * clng(n*1000) then
> n = formatnumber(n, 3)
> else
> n = formatnumber(n + 0.0005, 3)
> end if
CLng uses Banker's rounding, so it's wise to avoid in an ALWAYS up/down
scenario. Compare the following with this function:

roundUp(0.00105) --> 0.001
roundUp(0.00106) --> 0.002

[url]http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q196652&ID=KB;EN-US;Q196652[/url]

--
Dave Anderson

Unsolicited commercial email will be read at a cost of \$500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.

Dave Anderson Guest

6. ## Rounding Up

I am trying to get FMP to round up a number to the next whole.

Example:
You are making a 2,323 mile trip and your company buys you a hotel
room every 450 miles for the amount of \$80.00.

2323/450 returns a value of 5.16. I want to round this number to 6

Also, if the mileage is <450 then it should return a "0"

Bear in mind that the mileages are always different, the breakpoint
miles are always different and the dollar amounts are always
different.

Charlie McPherson Guest

7. ## Re: Rounding Up

(
Int(Mileage) +
(Int(Mileage) <> Mileage))
)*
(Mileage >449)

--
John Weinshel
Datagrace
Vashon Island, WA
(206) 463-1634
Associate Member, Filemaker Solutions Alliance

"Charlie McPherson" <rocktourearthlink.net> wrote in message
> I am trying to get FMP to round up a number to the next whole.
>
> Example:
> You are making a 2,323 mile trip and your company buys you a hotel
> room every 450 miles for the amount of \$80.00.
>
> 2323/450 returns a value of 5.16. I want to round this number to 6
>
> Also, if the mileage is <450 then it should return a "0"
>
> Bear in mind that the mileages are always different, the breakpoint
> miles are always different and the dollar amounts are always
> different.
>

John Weinshel Guest

8. ## Re: Rounding Up

> I am trying to get FMP to round up a number to the next whole.
>
> Example:
> You are making a 2,323 mile trip and your company buys you a hotel
> room every 450 miles for the amount of \$80.00.
>
> 2323/450 returns a value of 5.16. I want to round this number to 6
>
> Also, if the mileage is <450 then it should return a "0"
>
> Bear in mind that the mileages are always different, the breakpoint
> miles are always different and the dollar amounts are always
> different.
Charlie,
Create a separate breakpoints file with a record for every breakpoint,
fields mileage and amount, where the amount should be used from that
mileage upwards. So you start from mileage zero, amount zero. In your
main file create a relationship to this file based on the mileage fields
and lookup the amount through this relationship; if no match use next
lower value.
--
Hans Rijnbout
Utrecht, Netherlands
Hans Rijnbout Guest

9. ## Re: Rounding Up

Literally:

If (Mileage < Breakpoint, 0, (Int ((Mileage - 1) / Breakpoint) + 1) *
DollarAmount)

But are you really saying that if mileage is 449 you want \$0.00, if mileage
is 450 you want \$80.00 and if mileage is 451 you want \$160.00?

"Charlie McPherson" <rocktourearthlink.net> wrote in message
> I am trying to get FMP to round up a number to the next whole.
>
> Example:
> You are making a 2,323 mile trip and your company buys you a hotel
> room every 450 miles for the amount of \$80.00.
>
> 2323/450 returns a value of 5.16. I want to round this number to 6
>
> Also, if the mileage is <450 then it should return a "0"
>
> Bear in mind that the mileages are always different, the breakpoint
> miles are always different and the dollar amounts are always
> different.
>

Glenn Schwandt Guest

10. ## Re: Rounding Up

Thanks to all and this may be darn near impossible but here is a
(hopefully) more clear explaination...

Using 450 miles as a breakpoint and \$80 as a base payment;

0-449 miles = \$0
450-899 miles =\$80
900-1,349 miles = \$240
1,350-1,799 miles = \$320

or for another example using 500 miles as a breakpoint and \$100 as a
payment;

0-499 miles = \$0
500-999 miles = \$100
1,000-1,499 miles = \$200
and so forth

The fields I am using are...
Total miles to home (number)
Driver get a hotel room every ___ miles (number)

Hope this makes sense or is even possible.

Also, I have the code to do this in Visual Basic 6 if it would help

Thanks,
Charlie

"Glenn Schwandt" <schwandtgataoldot.com> wrote in message news:<vnllrv9s734063corp.supernews.com>...
> Literally:
>
> If (Mileage < Breakpoint, 0, (Int ((Mileage - 1) / Breakpoint) + 1) *
> DollarAmount)
>
> But are you really saying that if mileage is 449 you want \$0.00, if mileage
> is 450 you want \$80.00 and if mileage is 451 you want \$160.00?
>
> "Charlie McPherson" <rocktourearthlink.net> wrote in message
> > I am trying to get FMP to round up a number to the next whole.
> >
> > Example:
> > You are making a 2,323 mile trip and your company buys you a hotel
> > room every 450 miles for the amount of \$80.00.
> >
> > 2323/450 returns a value of 5.16. I want to round this number to 6
> >
> > Also, if the mileage is <450 then it should return a "0"
> >
> > Bear in mind that the mileages are always different, the breakpoint
> > miles are always different and the dollar amounts are always
> > different.
> >
Charlie McPherson Guest

11. ## Re: Rounding Up

OK, no cussin', but that's not exactly what you asked for originally!

(Also, I assume you meant 900-1,349 = \$160 and 1,350-1,799 = \$240)

TotalPayment (calculation, number) = Int( Total Miles / Breakpoint) * Base
Payment

"Charlie McPherson" <rocktourearthlink.net> wrote in message
> Thanks to all and this may be darn near impossible but here is a
> (hopefully) more clear explaination...
>
> Using 450 miles as a breakpoint and \$80 as a base payment;
>
> 0-449 miles = \$0
> 450-899 miles =\$80
> 900-1,349 miles = \$240
> 1,350-1,799 miles = \$320
>
> or for another example using 500 miles as a breakpoint and \$100 as a
> payment;
>
> 0-499 miles = \$0
> 500-999 miles = \$100
> 1,000-1,499 miles = \$200
> and so forth
>
> The fields I am using are...
> Total miles to home (number)
> Driver get a hotel room every ___ miles (number)
>
> Hope this makes sense or is even possible.
>
> Also, I have the code to do this in Visual Basic 6 if it would help
>
> Thanks,
> Charlie
>
> "Glenn Schwandt" <schwandtgataoldot.com> wrote in message
news:<vnllrv9s734063corp.supernews.com>...
> > Literally:
> >
> > If (Mileage < Breakpoint, 0, (Int ((Mileage - 1) / Breakpoint) + 1) *
> > DollarAmount)
> >
> > But are you really saying that if mileage is 449 you want \$0.00, if
mileage
> > is 450 you want \$80.00 and if mileage is 451 you want \$160.00?
> >
> > "Charlie McPherson" <rocktourearthlink.net> wrote in message
> > > I am trying to get FMP to round up a number to the next whole.
> > >
> > > Example:
> > > You are making a 2,323 mile trip and your company buys you a hotel
> > > room every 450 miles for the amount of \$80.00.
> > >
> > > 2323/450 returns a value of 5.16. I want to round this number to 6
> > >
> > > Also, if the mileage is <450 then it should return a "0"
> > >
> > > Bear in mind that the mileages are always different, the breakpoint
> > > miles are always different and the dollar amounts are always
> > > different.
> > >

Glenn Schwandt Guest

12. ## Re: Rounding Up

Thank You Glenn! You are a life saver.

Sorry about the bad math. Too many long days and sleepless nights.

Also, the VB6 code is about 20 lines long. This is so much better!

Thanks again,
Charlie
Charlie McPherson Guest

13. ## Re: Rounding Up

Hey Glenn,

First of all, thanks for all your help but I have one more small (I

The formula you gave me;

TotalPayment (calculation, number) = Int( Total Miles / Breakpoint) *
Base Payment works perfectly but there is another twist that I

If you are on a 1,323 mile trip that buys a hotel every 450 miles at
\$80, the formula figures it to pay \$160 or 2 hotel days or 900 miles.
The twist is that the driver gets yet another hotel for any additional
mileage over 900 but before the next breakpoint which would be 1,350
miles. In reality he would get 3 hotels instead of 2

This would be a payment of the full \$80 and not pro-rated base on the
amount of extra mileage between 900 and 1,323.

Example;

Leg 1: 0-450 miles = \$80

Leg 2: 451-900 miles = \$160

Leg 3: 901-1,323 = \$240

Then if the mileage was over 1,350 another \$80 would be due

I guess the sticky part is the \$0 for <450 miles

I tried a couple of things such as...

TotalPayment (calculation, number) = Int( Total Miles / Breakpoint) *
Base Payment + Base Payment but this gave the driver a hotel for less
than 450 miles

TotalPayment (calculation, number) = Int( Total Miles / Breakpoint) *
Base Payment +.99999 (and also +1) but this only added \$1 to the
final outcome.

This is how my calculation looks as is...

=(Int(Estimated Miles to Home/Driver gets a hotel every ___
miles)*Amount of Buy Out). These are the actual field names I am
using.

Sorry about the misinterpretation, sometimes this stuff gets a little
hairy.

Maybe one day I will be able to do this stuff myself.

Thanks again for all your help.

Charlie
Charlie McPherson Guest

14. ## Re: Rounding Up

"Charlie McPherson" <rocktourearthlink.net> wrote in message
> Hey Glenn,
>
> First of all, thanks for all your help but I have one more small (I
>
> The formula you gave me;
>
> TotalPayment (calculation, number) = Int( Total Miles / Breakpoint) *
> Base Payment works perfectly but there is another twist that I
>
> If you are on a 1,323 mile trip that buys a hotel every 450 miles at
> \$80, the formula figures it to pay \$160 or 2 hotel days or 900 miles.
> The twist is that the driver gets yet another hotel for any additional
> mileage over 900 but before the next breakpoint which would be 1,350
> miles. In reality he would get 3 hotels instead of 2
>
> This would be a payment of the full \$80 and not pro-rated base on the
> amount of extra mileage between 900 and 1,323.
>
> Example;
>
> Leg 1: 0-450 miles = \$80
>
> Leg 2: 451-900 miles = \$160
>
> Leg 3: 901-1,323 = \$240
>
> Then if the mileage was over 1,350 another \$80 would be due
>
> I guess the sticky part is the \$0 for <450 miles
>
> I tried a couple of things such as...
>
> TotalPayment (calculation, number) = Int( Total Miles / Breakpoint) *
> Base Payment + Base Payment but this gave the driver a hotel for less
> than 450 miles
>
> TotalPayment (calculation, number) = Int( Total Miles / Breakpoint) *
> Base Payment +.99999 (and also +1) but this only added \$1 to the
> final outcome.
>
> This is how my calculation looks as is...
>
> =(Int(Estimated Miles to Home/Driver gets a hotel every ___
> miles)*Amount of Buy Out). These are the actual field names I am
> using.
>
> Sorry about the misinterpretation, sometimes this stuff gets a little
> hairy.
>
> Maybe one day I will be able to do this stuff myself.
>
> Thanks again for all your help.
>
> Charlie

OK, but now we're back to my original response:

If (Estimated Miles to Home < Driver gets a hotel every ___ miles, 0, (Int
((Estimated Miles to Home - 1) / Driver gets a hotel every ___ miles) + 1) *

and question:

Are you really saying that if "Estimated Miles to Home" is 449 you want
\$0.00, if "Estimated Miles to Home" is 450 you want \$80.00 and if "Estimated
Miles to Home" is 451 you want \$160.00?

Glenn Schwandt Guest

15. ## Re: Rounding Up

Sorry Glenn but I think I am drowning in my own confusion! I believe
the first calculation is going to work fine.

In other words, 0-449 is 0, 450-899 is 1 and 900-1,349 is 3 and so
forth.

If there is a need for yet another buyout then the driver will just
have to 'adjust' his mileage to compensate.

Thank you again for all your help!
Charlie
> Are you really saying that if "Estimated Miles to Home" is 449 you want
> \$0.00, if "Estimated Miles to Home" is 450 you want \$80.00 and if "Estimated
> Miles to Home" is 451 you want \$160.00?
Charlie McPherson Guest

#### Posting Permissions

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