Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change currency format to show 4 decimal places instead of 2 globally

Tags:

c#

.net

I have a working website, where I use this expression everywhere.

price.ToString("C")

It currently shows 2 decimal places, eg. $1.45

Now I need the website to show 4 decimal places, eg. $1.4515

Is there any easy way to change it globally?

like image 870
Aximili Avatar asked Jun 13 '12 00:06

Aximili


People also ask

How do I change the Currency format in numbers?

On the Home tab, click the Dialog Box Launcher next to Number. Tip: You can also press Ctrl+1 to open the Format Cells dialog box. In the Format Cells dialog box, in the Category list, click Currency or Accounting. In the Symbol box, click the currency symbol that you want.

How do I show all decimal places in Excel?

By using a button: Select the cells that you want to format. On the Home tab, click Increase Decimal or Decrease Decimal to show more or fewer digits after the decimal point.


2 Answers

You can't modify the default behavior of the format specifier, but you can do a a global search-and-replace in your project. Assuming you're using Visual Studio, you can do a global search-and-replace (Ctrl-Shift-H) and replace .ToString("C") with .ToString("C4").

like image 172
Ethan Brown Avatar answered Sep 28 '22 13:09

Ethan Brown


Can you overwrite thread's CurrentCulture and set CurrencyDecimalDigits?

like image 29
Ilya Kozhevnikov Avatar answered Sep 28 '22 14:09

Ilya Kozhevnikov