Talk to Webmaster Tony John

### Online Members

Asheej T K
More...

Forums » .NET » .NET »

# Coverting decimal number to whole number in vb.net

Posted Date: 21 Jun 2012      Posted By:: Siva Shankar     Member Level: Silver    Member Rank: 1483     Points: 5   Responses: 5

I am developing student project. Here I am calculating marks for student. When I calculate average for a student it shows digits after decimal point. For

For Example
Avg=51.6,52.4,78.5 like this. I want to remove digits after decimal point or it should be converted as whole number Like This for Ex 51,72,53 etc. I want code in VB.NET

Here is my code.

u modify my code and reply me as soon as possible.

` For j = 0 To DataGridView1.Rows.Count - 1 For i = 2 To DataGridView1.Columns.Count - 5 tot = tot + DataGridView1.Rows(j).Cells(i).Value If DataGridView1.Columns(i + 1).Name = "Total" Then DataGridView1.Rows(j).Cells(i + 1).Value = tot DataGridView1.Columns(i + 1).ReadOnly = True k = i End If Next DataGridView1.Rows(j).Cells(k + 2).Value = Math.Truncate(tot/k* 10) / 10 ' DataGridView1.Rows(j).Cells(k + 2).Value = tot / k DataGridView1.Columns(k + 2).ReadOnly = True tot = 0`

# Responses

 #676789    Author: Anil Kumar Pandey      Member Level: Platinum      Member Rank: 1     Date: 22/Jun/2012   Rating:     Points: 2 You can make use of the Floor function to change this to Whole numbers`DataGridView1.Rows(j).Cells(k + 2).Value =(Math.Floor( Math.Truncate(tot/k* 10) / 10).ToString();' DataGridView1.Rows(j).Cells(k + 2).Value = tot / k`Thanks & RegardsAnil Kumar PandeyMicrosoft MVP, DNS MVM

 #676792    Author: Siva Shankar      Member Level: Silver      Member Rank: 1483     Date: 22/Jun/2012   Rating:     Points: 1 Sorry again i am facing the same problem

 #676928    Author: Ravindran        Member Level: Diamond      Member Rank: 3     Date: 22/Jun/2012   Rating:     Points: 2 Are you try Math.Round like below code`DataGridView1.Rows(j).Cells(k + 2).Value = Math.Round(Math.Round(tot/k* 10) / 10).ToString()`RegardsN.RavindranYour Hard work never fails

 #676953    Author: Siva Shankar      Member Level: Silver      Member Rank: 1483     Date: 22/Jun/2012   Rating:     Points: 0 Really thanks for u ma.U r really appreciated.

#677131    Author: Ultimaterengan        Member Level: Gold      Member Rank: 9     Date: 24/Jun/2012   Rating:     Points: 2

`'To get without round up Dim d As Decimal = 78.9 Dim i As Integer = Convert.ToInt32(d) 'this code will give with round up Dim d1 As Decimal = 78.9 Dim j As Integer = Math.Round(d1)`

#### Thanks & RegardsG.RenganathanNothing is mine ,Everything is yours!!!

http://renganathan1984.blogspot.com/