| | |
Format to 2 decimal places
Please support our VB.NET advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
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: 2250 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for VB.NET
"crystal .net .net2005 2008 access add application array assignment basic box button buttons center class click code combo convert cpu data database datagrid datagridview design designer dissertation dissertations dissertationthesis dosconsolevb.net editvb.net employees error excel exists firewall function image images isnumericfuntioncall listview login map math memory mobile module msaccess mssqlbackend mysql navigate net opacity page pan picturebox port print printing printpreview problem record refresh regex reports" reuse right-to-left save savedialog search serial socket sorting sql sqldatbase storedprocedure string structures studio temp textbox timer txttoxmlconverter upload useraccounts usercontol usercontrol vb vb.net vb.nettoolboxvisualbasic2008sidebar vb2008 vbnet vista visual visualbasic visualbasic.net visualstudio2008 web wpf xml






