| | |
Format to 2 decimal places
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2009
Posts: 7
Reputation:
Solved Threads: 0
Hi, sorry to ask this, I know it has been asked before but despite reading the answers I still dont get it. I am using visual studio 2008, vb.net.
I have a lable, label1. I want it to display the results of a calculation, a/b. The answer is a number typically 0.xxxxxxxxxx . I want the answer displayed to two decimal places in lable1. How do I achieve that please?
Thanks for all and any help.
I have a lable, label1. I want it to display the results of a calculation, a/b. The answer is a number typically 0.xxxxxxxxxx . I want the answer displayed to two decimal places in lable1. How do I achieve that please?
Thanks for all and any help.
vb.net Syntax (Toggle Plain Text)
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim bigNumber As Decimal = 1234567.123456 Console.WriteLine("F2: " & bigNumber.ToString("F2")) Console.WriteLine("N2: " & bigNumber.ToString("N2")) 'Likewise: TextBox1.Text = bigNumber.ToString("F2") End Sub
Results in:
VB.NET Syntax (Toggle Plain Text)
F2: 1234567.12 N2: 1,234,567.12
So use F2 to not include a thousands separator, N2 will include it
•
•
Join Date: May 2009
Posts: 7
Reputation:
Solved Threads: 0
Thank you for your reply, but the answer does not seem to be working for me.
In my code I have
And I cannot get the text in label24 to format to 2 decimal places.
What am I doing wrong or have not grasped please. THank you again
In my code I have
dim a as double dim b as double ' 'some calculation here wich typically results in 'a/b being 0.xxxxxxx ' label24.text =a/b
And I cannot get the text in label24 to format to 2 decimal places.
What am I doing wrong or have not grasped please. THank you again
•
•
Join Date: Apr 2008
Posts: 45
Reputation:
Solved Threads: 10
•
•
Join Date: Jun 2009
Posts: 59
Reputation:
Solved Threads: 4
you can try this hope it will work for you.
or try this
try both hope it works with you
VB.NET Syntax (Toggle Plain Text)
label24.text =Math.Round(a/b, 2)
or try this
VB.NET Syntax (Toggle Plain Text)
label24.text = Format(a/b, "0.00")
try both hope it works with you
![]() |
Similar Threads
- Format Decimal (C#)
- Two Decimal Places (VB.NET)
- Decimal places-Need Help (Java)
- Need More Than 5 Decimal Places!! (C++)
- problem with decimal places (Visual Basic 4 / 5 / 6)
- C++ question(Decimal places)very weird (C++)
- Excel97 decimal places (Windows Software)
Other Threads in the VB.NET Forum
- Previous Thread: Help about my statement
- Next Thread: Function placement
Views: 2223 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for VB.NET
.net 2005 2008 access account application arithmetic array arrays basic bing button buttons c# center check checkbox code combobox component convert crystalreport data database databasesearch datagrid datagridview design designer dissertation dissertations dropdownlist excel file-dialog folder ftp generatetags google gridview hardcopy highlighting images inline insert installer intel internet listview mobile monitor ms net networking output passingparameters peertopeervideostreaming picturebox picturebox1 plugin port print printing problem problemwithinstallation project save searchbox searchvb.net select serial server soap sorting studio syntax table tcp text textbox time timer toolbox trim update updown user vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web wpf






