2010-04-03 90 views

回答

9
Math.Truncate(myDecimal) 

将剥去的小数部分,只留下一部分(而不是改变类型;即,这将返回该参数的类型,以及,是它DoubleDecimal) 。

3

将其转换为整数。

Dim myDec As Decimal 
myDecimal = 532.016 
Dim i As Integer = Cint(myDecimal) 

'i now contains 532 
+0

请问我可以让我知道关于如何做到这一点的整个代码 – 2010-04-03 20:15:47

+0

OP根据问题的标题使用了Decimal。 – Joey 2010-04-03 20:22:26

+0

@JohannesRössel - 比我的眼睛更锐利......答案更正了 – Oded 2010-04-03 20:35:56

0

你可以使用System.Text.RegularExpressions:

Imports System.Text.RegularExpressions 'You need this for "Split"' 

Public Class Form1 

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 

     Dim yourNumber As String = 532.016 'You could write your integer as a string or convert it to a string' 
     Dim whatYouWant() As String 'Notice the "(" and ")", these are like an array' 

     whatYouWant = Split(yourNumber, ".") 'Split by decimal' 
     MsgBox(whatYouWant(0)) 'The number you wanted is before the first decimal, so you want array "(0)", if wanted the number after the decimal the you would write "(1)"' 

    End Sub 

End Class