truncate decimal part in float value value in vb.net

Smith
Smith
None
2568 Points
74 Posts

Hi,

what is best way to truncate decimal part in float value value in vb.net?

Views: 9152
Total Answered: 2
Total Marked As Answer: 0
Posted On: 27-Sep-2015 22:25

Share:   fb twitter linkedin
Answers
Brian
Brian
Moderator
2232 Points
14 Posts
         

Hi Smith,

There is no such method in vb.net. You have to create custom method as:

Public Shared Function TruncateDecimal(DecimalValue As Single, DecimalNumber As Integer) As Single
Dim DecimalPart As String
Dim IntegerPart As String
DecimalPart = (DecimalValue - Math.Truncate(DecimalValue))
IntegerPart = Math.Truncate(DecimalValue)
DecimalPart = DecimalPart.Substring(2, DecimalNumber)
Return Convert.ToSingle(IntegerPart & "." & DecimalPart)
End Function
Posted On: 28-Sep-2015 00:47
Rahul Maurya
Rahul M...
Teacher
4822 Points
23 Posts
         

Hi smith,

You can use the following simple code as:

If you want to truncate decimal part after four digit then you can do following:

DecimalValue = Math.Truncate(DecimalValue * 10000)
DecimalValue = DecimalValue / 10000

 

Posted On: 09-Oct-2015 02:15
 Log In to Chat