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. [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => <47db01c340db$5ae0e710$a401280a@phx.gbl> <#DgtD1NQDHA.2832@TK2MSFTNGP10.phx.gbl> [htmlstate] => on_nl2br [postusername] => Dave Anderson [ip] => GTSPXOESSGOQ@sp [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 5 [islastshown] => [isfirstshown] => [attachments] => [allattachments] => ) --> Rounding Up - ASP

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...

Sponsored Links
  1. #1

    Default 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
    Sponsored Links
    Brent Bortnick Guest

  2. #2

    Default 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. #3

    Default 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. #4

    Default 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.
    (Please change the x'es to dots in my emailaddress)
    Evertjan. Guest

  5. #5

    Default 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. #6

    Default 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.

    Thanks in advance for all your help
    Charlie McPherson Guest

  7. #7

    Default 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
    news:c4a0c30.0309301340.3b5554b8posting.google.co m...
    > 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.
    >
    > Thanks in advance for all your help

    John Weinshel Guest

  8. #8

    Default Re: Rounding Up

    Charlie McPherson <rocktourearthlink.net> wrote:
    > 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. #9

    Default 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
    news:c4a0c30.0309301340.3b5554b8posting.google.co m...
    > 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.
    >
    > Thanks in advance for all your help

    Glenn Schwandt Guest

  10. #10

    Default 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)
    Amount of buy-out (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
    and please, no cussin'

    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
    > news:c4a0c30.0309301340.3b5554b8posting.google.co m...
    > > 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.
    > >
    > > Thanks in advance for all your help
    Charlie McPherson Guest

  11. #11

    Default 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
    news:c4a0c30.0310021155.1341762fposting.google.co m...
    > 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)
    > Amount of buy-out (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
    > and please, no cussin'
    >
    > 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
    > > news:c4a0c30.0309301340.3b5554b8posting.google.co m...
    > > > 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.
    > > >
    > > > Thanks in advance for all your help

    Glenn Schwandt Guest

  12. #12

    Default 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. #13

    Default Re: Rounding Up

    Hey Glenn,



    First of all, thanks for all your help but I have one more small (I
    hope) favor to ask.



    The formula you gave me;

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



    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. #14

    Default Re: Rounding Up

    "Charlie McPherson" <rocktourearthlink.net> wrote in message
    news:c4a0c30.0310031933.12930225posting.google.co m...
    > Hey Glenn,
    >
    > First of all, thanks for all your help but I have one more small (I
    > hope) favor to ask.
    >
    > The formula you gave me;
    >
    > TotalPayment (calculation, number) = Int( Total Miles / Breakpoint) *
    > Base Payment works perfectly but there is another twist that I
    > completely forgot about.
    >
    > 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) *
    Amount of Buy Out)



    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. #15

    Default 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

Similar Threads

  1. Rounding to nearest 100
    By ccnorris in forum Coldfusion - Advanced Techniques
    Replies: 4
    Last Post: May 30th, 11:44 PM
  2. Rounding off
    By Mike Blezien in forum PERL Beginners
    Replies: 1
    Last Post: November 22nd, 11:22 PM
  3. how to keep decimals from rounding
    By Rob Yelvington in forum PHP Development
    Replies: 3
    Last Post: August 26th, 04:58 PM
  4. [PHP] Rounding issue
    By Larry E . Ullman in forum PHP Development
    Replies: 3
    Last Post: July 29th, 10:21 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139