Subscribe to Subscribers
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: 2 out of 52 out of 5     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 & Regards
Anil Kumar Pandey
Microsoft MVP, DNS MVM



 
#676792    Author: Siva Shankar      Member Level: Silver      Member Rank: 1483     Date: 22/Jun/2012   Rating: 2 out of 52 out of 5     Points: 1

Sorry again i am facing the same problem


 
#676928    Author: Ravindran        Member Level: Diamond      Member Rank: 3     Date: 22/Jun/2012   Rating: 2 out of 52 out of 5     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()


Regards
N.Ravindran
Your Hard work never fails






 
#676953    Author: Siva Shankar      Member Level: Silver      Member Rank: 1483     Date: 22/Jun/2012   Rating: 2 out of 52 out of 5     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: 2 out of 52 out of 5     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 & Regards
G.Renganathan
Nothing is mine ,Everything is yours!!!


http://renganathan1984.blogspot.com/



 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Next : ERROR [HYT00] [Microsoft][ODBC SQL Server Driver]Timeout expired
Previous : Highlight color in richtextbox
Return to Discussion Forum
Post New Message
Category:

Related Messages
Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
2005 - 2012 All Rights Reserved.
.NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
Articles, tutorials and all other content offered here is for educational purpose only.
We are not associated with Microsoft or its partners.