简体   繁体   中英

C# Getting values from text file and parsing them to have currency symbol in a List Box

I wanted to know how to add a currency symbol to a parsed value that was put into a List<> to display it in a "$18.00" format rather than 18.0 which is what I have now.

I tried .ToString("N2") but it's not that simple. I'll copy and paste what I currently have, I'm not too good of a programmer so bear with me.

I get no errors but I tried tossing the .ToString at the end but naturally it can't be that symbol. Any help would be appreciated!

currentItem.Price = decimal.Parse(strArray[2]);

Try this

currentItem.Price = decimal.Parse(strArray[2]).ToString("C");

More info here https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.110).aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM