Results 1 to 21 of 21

Thread: URGENT's NOT THE WORD! UNRESOLVED

  1. #1

    Thread Starter
    Fanatic Member VisionIT's Avatar
    Join Date
    Nov 2002
    Location
    Workin'...
    Posts
    718

    URGENT's NOT THE WORD! UNRESOLVED

    Simple... and yet I can't figure it!

    I have a number in a field like this...

    5.425

    I need to round this number up to 5.43, so i used this command...

    boxVAT = round(boxvat, 2)

    When I run the package it rounds it down to 5.42, which means all the balances are 1 penny out...

    HELP.

    Anyone any ideas? Don't say add a penny on either

    Regards,

    Paul.
    Last edited by VisionIT; Jan 28th, 2003 at 08:41 AM.

  2. #2
    Frenzied Member Lightning's Avatar
    Join Date
    Oct 2002
    Location
    Eygelshoven
    Posts
    1,611
    Add 0.005 to the value so that the round-up goes is always correct

  3. #3

    Thread Starter
    Fanatic Member VisionIT's Avatar
    Join Date
    Nov 2002
    Location
    Workin'...
    Posts
    718
    nice idea... but it still doesn't work M8...

    The ROUND feature should automatically round up the number if it's end's with x.xx5. Is this a fault with VB?

    Thanks guys...

    Regards,

    Paul.

  4. #4
    Addicted Member mr_metal_hed's Avatar
    Join Date
    Aug 2002
    Location
    NC
    Posts
    149
    Yup. It evaluates incorrectly. I did a quick search concerning this and found another fellow that wanted an answer. He decided to use this function. It's not mine, so I haven't checked it's speed or efficiency. I hope it helps.
    VB Code:
    1. Public Function RoundIt(Number As Variant, NumDigitsAfterDecimal As Long) As Variant
    2.    If Not IsNumeric(Number) Then
    3.        RoundIt = Number
    4.    Else
    5.        RoundIt = Int(0.5 + Number * (10 ^ NumDigitsAfterDecimal)) / (10 ^ NumDigitsAfterDecimal)
    6.    End If
    7. End Function

  5. #5
    Member
    Join Date
    Oct 2002
    Location
    South Africa
    Posts
    47
    Hi

    have you tried FormatNumber:

    FormatNumber(5.075, 2) = 5.08
    FormatNumber(5.074,2) = 5.07

    Hope this solve the problem

  6. #6

    Thread Starter
    Fanatic Member VisionIT's Avatar
    Join Date
    Nov 2002
    Location
    Workin'...
    Posts
    718
    Tried that too M8... still didn't work.

    Thanks for that code m8, but again... it still refuses to round it properly. I might just get a paper & pen!

    ANYONE... PLEASE...

    Regards,

    Paul.

  7. #7
    Addicted Member mr_metal_hed's Avatar
    Join Date
    Aug 2002
    Location
    NC
    Posts
    149
    Here is a post at another forum that may provide some help.

  8. #8
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    The best description I have seen of this issue / problem / opportunity is at: http://support.microsoft.com/default...;en-us;q196652

  9. #9
    Frenzied Member KayJay's Avatar
    Join Date
    Jul 2001
    Location
    Chennai
    Posts
    1,849
    The issue crops up only when the last number after the decimal point is exactly 5. Less than 5 get rounded down, greater than 5 get rounded up. Best solution is to write Ur own Round function, which changes the last number to 6 or 4 (depending on how U want the rounding done) and then use the inbuilt to round off the resultant number.

    HTH

    "Brothers, you asked for it."
    ...Francisco Domingo Carlos Andres Sebastian D'Anconia

  10. #10
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    Originally posted by JordanChris
    The best description I have seen of this issue / problem / opportunity is at: http://support.microsoft.com/default...;en-us;q196652
    yeah use this link.. if you can't find a round function in here to fit ya.. it probably doesn't exist

    that KB article saved me once before

  11. #11

    Thread Starter
    Fanatic Member VisionIT's Avatar
    Join Date
    Nov 2002
    Location
    Workin'...
    Posts
    718
    Thankyou all for the help... and i've managed to get a one day extension on the package, so i'll keep trying!

    All the best,

    Paul.

  12. #12
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    Kleinma, did you see the following comment:
    Visual Basic for Applications does not have any function that does arithmetic rounding.

    I once wrote the following function to implement arithmetic rounding:
    VB Code:
    1. Public Function MyRound(ByVal Number As Double, Optional ByVal NumDigitsAfterDecimal As Long = 0) As Double
    2.     MyRound = Fix((Number * (10 ^ NumDigitsAfterDecimal)) + (Sgn(Number) * 0.5)) / (10 ^ NumDigitsAfterDecimal)
    3. End Function

  13. #13
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    Originally posted by Frans C
    Kleinma, did you see the following comment:
    Visual Basic for Applications does not have any function that does arithmetic rounding.

    I once wrote the following function to implement arithmetic rounding:
    VB Code:
    1. Public Function MyRound(ByVal Number As Double, Optional ByVal NumDigitsAfterDecimal As Long = 0) As Double
    2.     MyRound = Fix((Number * (10 ^ NumDigitsAfterDecimal)) + (Sgn(Number) * 0.5)) / (10 ^ NumDigitsAfterDecimal)
    3. End Function
    ??? huh? are you talking about in that KB article? they have about 10 different types of custom rounding functions

  14. #14
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    Sorry, I read the article to fast. I missed the custom functions.
    My function is similar to the SymArith function.

  15. #15
    Lively Member
    Join Date
    Sep 2000
    Posts
    79
    NO sure if this is what you need, I dunno, I never have been great at this VB stuff

    I put this on a form with a textbox for ur value, a label for the result and a button to do the crunching stuff:



    Private Sub cmdRound_Click()
    Dim MyNumber As Currency
    Dim MyRoundedNumber As Currency
    Dim TestValue As String


    MyNumber = CCur(txtNumber.Text)
    TestValue = CStr(MyNumber)
    If Right(TestValue, 1) = "5" Then
    MyNumber = MyNumber + 0.001
    End If



    MyRoundedNumber = Round(MyNumber, 2)

    lblNumber.Caption = CStr(MyRoundedNumber)



    End Sub

    It seems to work, but try it out


    Paul Moore
    The problem with designing something completely foolproof is to underestimate the ingenuity of a complete fool. - Douglas Adams

    I know the human being and fish can coexist peacefully. - GWB

    I think we agree, the past is over. - GWB

  16. #16
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Thumbs up

    Originally posted by Frans C
    Sorry, I read the article to fast. I missed the custom functions.
    My function is similar to the SymArith function.
    its all good.. i just got a little confused for a second

  17. #17

    Thread Starter
    Fanatic Member VisionIT's Avatar
    Join Date
    Nov 2002
    Location
    Workin'...
    Posts
    718
    Originally posted by Mav505
    NO sure if this is what you need, I dunno, I never have been great at this VB stuff
    Genius!

    I haven't tried it (yet), but the code looks perfect. I'm in the middle of a server crisis ATM, but i'll try it l8er.

    Cheers.

    What's your address M8y... there's a cheque in the post!

    Regards,

    Paul.

  18. #18
    Frenzied Member KayJay's Avatar
    Join Date
    Jul 2001
    Location
    Chennai
    Posts
    1,849
    Originally posted by Mav505
    NO sure if this is what you need, I dunno, I never have been great at this VB stuff

    I put this on a form with a textbox for ur value, a label for the result and a button to do the crunching stuff:



    Private Sub cmdRound_Click()
    Dim MyNumber As Currency
    Dim MyRoundedNumber As Currency
    Dim TestValue As String


    MyNumber = CCur(txtNumber.Text)
    TestValue = CStr(MyNumber)
    If Right(TestValue, 1) = "5" Then
    MyNumber = MyNumber + 0.001
    End If



    MyRoundedNumber = Round(MyNumber, 2)

    lblNumber.Caption = CStr(MyRoundedNumber)



    End Sub

    It seems to work, but try it out


    Paul Moore
    My post earlier

    "Brothers, you asked for it."
    ...Francisco Domingo Carlos Andres Sebastian D'Anconia

  19. #19
    Lively Member
    Join Date
    Sep 2000
    Posts
    79
    Not a problem sir, always glad to help another Paul Moore (I'm one too ), Hope it works out for ya.



    Paul Moore
    The problem with designing something completely foolproof is to underestimate the ingenuity of a complete fool. - Douglas Adams

    I know the human being and fish can coexist peacefully. - GWB

    I think we agree, the past is over. - GWB

  20. #20

    Thread Starter
    Fanatic Member VisionIT's Avatar
    Join Date
    Nov 2002
    Location
    Workin'...
    Posts
    718
    Another Paul Moore? Hmm...

    We could start another dave gorman style show ! How many Paul Moore's in the world?

    Something to think about.

    Regards,

    The original Paul Moore

  21. #21
    Lively Member UnderTheTable's Avatar
    Join Date
    Jan 2003
    Location
    beside HeLL
    Posts
    113

    Talking round....

    In vb or any other development tools use the same logic......

    if the decimal value is not more than 5 then it will not round with the highest value....

    i suppose this is also a mathematical logic....

Posting Permissions

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



Click Here to Expand Forum to Full Width