Pradeep Gaur
Pradeep Gaur

Reputation: 573

Formatting currency in .NET

I am formatting the currency using Tostring() method i m using following syntax

ToString('##.##') it is working perfectly but in case of round number it remove last 2 zero

like for 100 it does not show 100.00 is shows 100.

how can i format in that way means input desired output 100 100.00 100.10 100.10

Upvotes: 3

Views: 3558

Answers (5)

n8wrl
n8wrl

Reputation: 19765

This might help. Might be more than you need, but it takes globalization into account which might be necessary. "C" is also a short-cut currency format string that might get you further along.

Upvotes: 0

Jim
Jim

Reputation: 2146

Also, if you don't want the currency sign ($ in the US) added that "C" gives, you can also use "F2", which is "fixed number with 2 decimal places". It also has the advantage of giving you a thousands separator when you results go over 1,000.00.

Upvotes: 1

alexl
alexl

Reputation: 6851

You can use :

.ToString("C")

Hope it helps.

Upvotes: 0

taylonr
taylonr

Reputation: 10790

First google result.

String.Format("{0:C}", x.ToString());

http://www.howtogeek.com/howto/programming/format-a-string-as-currency-in-c/

Upvotes: 3

Øyvind Bråthen
Øyvind Bråthen

Reputation: 60694

Try "##.00" instead.

That will force two digits after the decimal separator.

You can also use ToString("C") to use the culture specific format in Windows directly.

Upvotes: 4

Related Questions