Function to Remove the Decimal Places
Of what i remember use the Int() function. ex
int(2.99) = 2 ; int(2.1)=2
and so on.
be careful that CInt() actually rounds the number, but Int() doesn't.
CInt(1.6) ~~ 2Int(1.6) ~~ 1
It's Round()
Sub Sample() Dim dval As Double dval = 1.12345 Debug.Print Round(dval, 0)End Sub
0
above specifies the number of decimals you want.
EDIT:
Albi Patozi is right. The equivalent
of Math.Floor()
is int()
. I was under the impression that you just wanted to return a number without the decimals. But then I looked up http://www.w3schools.com/jsref/jsref_floor.asp
The floor() method rounds a number DOWNWARDS to the nearest integer, and returns the result.
'~~> JavaScript floor() Method'var a=Math.floor(0.60); ~~> 0'var b=Math.floor(0.40); ~~> 0'var c=Math.floor(5); ~~> 5'var d=Math.floor(5.1); ~~> 5'var e=Math.floor(-5.1); ~~> -6'var f=Math.floor(-5.9); ~~> -6Sub Sample() Dim dval(5) As Double, i As Long dval(0) = 0.6: dval(1) = 0.4: dval(2) = 5 dval(3) = 5.1: dval(4) = -5.1: dval(5) = -5.9 For i = LBound(dval) To UBound(dval) Debug.Print Round(dval(i), 0); " ~~ "; Int(dval(i)) NextEnd Sub
RESULT
ROUND() ~~ INT()
1 ~~ 0
0 ~~ 0
5 ~~ 5
5 ~~ 5
-5 ~~ -6
-6 ~~ -6