|
-
Jan 28th, 2003, 08:27 AM
#1
Thread Starter
Fanatic Member
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.
-
Jan 28th, 2003, 08:33 AM
#2
Add 0.005 to the value so that the round-up goes is always correct
-
Jan 28th, 2003, 08:41 AM
#3
Thread Starter
Fanatic Member
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.
-
Jan 28th, 2003, 08:43 AM
#4
Addicted Member
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:
Public Function RoundIt(Number As Variant, NumDigitsAfterDecimal As Long) As Variant
If Not IsNumeric(Number) Then
RoundIt = Number
Else
RoundIt = Int(0.5 + Number * (10 ^ NumDigitsAfterDecimal)) / (10 ^ NumDigitsAfterDecimal)
End If
End Function
-
Jan 28th, 2003, 08:45 AM
#5
Member
Hi
have you tried FormatNumber:
FormatNumber(5.075, 2) = 5.08
FormatNumber(5.074,2) = 5.07
Hope this solve the problem
-
Jan 28th, 2003, 08:50 AM
#6
Thread Starter
Fanatic Member
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.
-
Jan 28th, 2003, 08:53 AM
#7
Addicted Member
Here is a post at another forum that may provide some help.
-
Jan 28th, 2003, 09:00 AM
#8
Frenzied Member
The best description I have seen of this issue / problem / opportunity is at: http://support.microsoft.com/default...;en-us;q196652
-
Jan 28th, 2003, 09:07 AM
#9
Frenzied Member
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
-
Jan 28th, 2003, 09:29 AM
#10
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
-
Jan 28th, 2003, 09:39 AM
#11
Thread Starter
Fanatic Member
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.
-
Jan 28th, 2003, 10:10 AM
#12
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:
Public Function MyRound(ByVal Number As Double, Optional ByVal NumDigitsAfterDecimal As Long = 0) As Double
MyRound = Fix((Number * (10 ^ NumDigitsAfterDecimal)) + (Sgn(Number) * 0.5)) / (10 ^ NumDigitsAfterDecimal)
End Function
-
Jan 28th, 2003, 10:15 AM
#13
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:
Public Function MyRound(ByVal Number As Double, Optional ByVal NumDigitsAfterDecimal As Long = 0) As Double
MyRound = Fix((Number * (10 ^ NumDigitsAfterDecimal)) + (Sgn(Number) * 0.5)) / (10 ^ NumDigitsAfterDecimal)
End Function
??? huh? are you talking about in that KB article? they have about 10 different types of custom rounding functions
-
Jan 28th, 2003, 10:37 AM
#14
Sorry, I read the article to fast. I missed the custom functions.
My function is similar to the SymArith function.
-
Jan 28th, 2003, 11:02 AM
#15
Lively Member
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
-
Jan 28th, 2003, 11:15 AM
#16
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
-
Jan 28th, 2003, 12:45 PM
#17
Thread Starter
Fanatic Member
-
Jan 28th, 2003, 12:59 PM
#18
Frenzied Member
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
-
Jan 29th, 2003, 04:42 AM
#19
Lively Member
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
-
Jan 29th, 2003, 05:27 AM
#20
Thread Starter
Fanatic Member
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
-
Jan 29th, 2003, 06:20 AM
#21
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|