Anyone know how to truncate a decimal off using code?(can't round)
Anyone know how to truncate a decimal off using code?(can't round)
Hello Skrimpy,
To workaround this problem requires using strings. The code sample shows how to truncated without rounding.
'N is the Decimal Number (whole or fraction) to truncate
NbrStr = Str(N)
I = InStr(1, NbrStr, ".")
N = Val(Left(NbrStr, X - 1))
Where there is a will, there is a way,
Leith Ross
Why not just use the Int function? It returns the integer part of a number
Please Login or Register to view this content.
Definitely use Int, you could do this:
TJPlease Login or Register to view this content.
PS You could also just use Application.WorksheetFunction.Trunc
Hello,
The best and easiest method is to use the ROUND worksheet function...
Result = WorksheetFunction.Round(Number, Significant Digits)
This can be used with the worksheet formulas...
=ROUND(Number, Significant Digits)
Just another way to do it,
Leith Ross
But, Round() does not truncate, it rounds!
TJ
I tried this. It was not recognized. Is this another one of those functions that aren't available unless you go to tools and add-ins, like the "Analysis Tool Pak"?Originally Posted by tinyjack
Well, I have to admit I did not try it and much to my surprise it is not supported by Application.WorksheetFunction. Learn something new everyday.
I trust the rest of the post has solved your problem.
TJ
Int is a VBA function.
And INT is a worksheet function that, as far as I know is available without any add-ins needed.
I think that is not supported by WorkSheetFunction is because it is a VBA function.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks