Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String.Format in conjunction with CultureInfo C#

I want to format a price using string.Format. I am able to get the correct currency symbol but can't figure out the regex to always have 2 decimal places regardless if they are 0s. Here is my code:

 CultureInfo us = CultureInfo.GetCultureInfo("en-US");
 price.text = string.Format(us, "{0:C}",inventory.priceTotal);
like image 923
Lewis Seddon Avatar asked Feb 23 '17 14:02

Lewis Seddon


1 Answers

Add 2 to C so C2

string.Format(us, "{0:C2}",inventory.priceTotal);

See also Standard Numeric Format Strings

like image 157
Igor Avatar answered Nov 01 '22 09:11

Igor