i have 532.016 i want to get only 532 part in vb.net how can i do that
+3
A:
Cast it to an Integer.
Dim myDec As Decimal
myDecimal = 532.016
Dim i As Integer = Cint(myDecimal)
'i now contains 532
Oded
2010-04-03 20:14:25
could you please let me know the whole code about how to do that
Web Worm
2010-04-03 20:15:47
The OP was using Decimal, according to the title of the question.
Joey
2010-04-03 20:22:26
@Johannes Rössel - sharper eyes than mine... Answer corrected
Oded
2010-04-03 20:35:56
+9
A:
Math.Truncate(myDecimal)
will strip away the fractional part, leaving only the integral part (while not altering the type; i. e. this will return the type of the argument as well, be it Double
or Decimal
).
Joey
2010-04-03 20:20:35
A:
You could use 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
typoknig
2010-04-04 06:44:21