שתף באמצעות


VB: How do i format two decimal places?

Question

Tuesday, March 3, 2015 11:38 PM

I'm using VB in Visual Studio 2013.

The professor wants the answers from the textboxes to be displayed with dwo decimal places. 

all he gave us was the following syntax:

format (#,#.00)

however i have no idea how to get this to work as i tried to figure it out on my own and nothing. i would like it to be displayed with the dollar symbol if possible with the comma separators when needed.

i tried declaring a variable as a string and a double but i kept coming to a dead end. help please. this is the last thing i need to turn this in tomorrow.

All replies (7)

Wednesday, March 4, 2015 9:09 AM ✅Answered | 1 vote

Hi wilmer0072012,

-->i would like it to be displayed with the dollar symbol if possible with the comma separators when needed.

Dim value As Decimal = 16325.62d
Dim specifier As String 

specifier = "C"
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier))
' Results:    C: $16,325.62

If you want to display a decimal value to other formats, you could refer to the following article.

#Decimal.ToString Method (String)
https://msdn.microsoft.com/en-us/library/fzeeb5cd(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1

Best regards,
Youjun Tang

We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.


Wednesday, March 4, 2015 8:44 AM

Hi wilmer0072012,

Thank you for posting in MSDN forum.

Since this issue is related to the VB, so we will move this case to the VB forum: https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=vbgeneral , you will get better support.

Best Regards,

We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.


Wednesday, March 4, 2015 9:08 AM

Yea Wilmar, 

That is always difficult if you ask a question to a forum, here you would receive an answer like use the overridden and overloade method from ToString (a base method from object). 

Howevever, your teacher asks something from the format method, a little bit older, but if you want information than use a search engine and type than something likewise format .Net string method

It finds than this.

https://msdn.microsoft.com/en-us/library/system.string.format%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

That has in fact all the information and samples you need. Be aware your teachers code is not complete.

Success
Cor


Wednesday, March 4, 2015 10:29 AM

Hi guys,

I don't know how long is your forum experience. 

But there is a long time etiquette in the forums, which stands from the first day of newsgroups not to help people with code for homework.

Do you real think I could not do that?

Now it took me more time, but probably a wast because your replies.


Success
Cor

Success
Cor


Wednesday, March 4, 2015 10:33 AM

@Cor, true,  wasn't paying attention there, I stand corrected
, deleted my post :-)


Wednesday, March 4, 2015 11:54 AM

Hello,

In the future when having issues finding a solution to a problem in regards to homework it is best to use a well thought out search phrase.

Examples

vb.net format decimal currency

vb.net format decimal to money

If you are pursuing a career as a software developer you will need to be good at finding information. In the case of VB.NET or C# always begin by searching through the MSDN document web site then if not located search the web while this forum here is great many times we as developers can find solutions without using the forums. 

Also, never assume a value in a TextBox can be converted to an integer, decimal, double etc. This may or may not have been taught but if not at least you have been informed it is wise to check first before performing formatting.

Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.


Wednesday, March 4, 2015 5:03 PM

Hi wilmer0072012,

-->i would like it to be displayed with the dollar symbol if possible with the comma separators when needed.

Dim value As Decimal = 16325.62d
Dim specifier As String 

specifier = "C"
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier))
' Results:    C: $16,325.62

If you want to display a decimal value to other formats, you could refer to the following article.

#Decimal.ToString Method (String)
https://msdn.microsoft.com/en-us/library/fzeeb5cd(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1

Best regards,
Youjun Tang

We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.

that you so much this was all i needed. i would never have been able to figure that out by looking up information because with everything i had already found i still wasn't able to figure it out or understand.

but now i do with your help.

i got all the text boxes working like i wanted now. thanks for the help.