|
-
October 29th, 2010, 04:27 PM
#1
Currency formatting
Hi,
I have some currency values to be formatted. They are stored as double and when I use String.Format("{0:C2}", strValue); it does NOT yield the right results.
I need all the values to be formatted to decimal places e.g 124 as 124.00 and 123.45 as 123.45 itself. I also want the -values to be surrounded by parenthesis. I knew how to do this in VB but not in C#! Like -123.56 should be (123.56) and -34 should (34.00).
I read some articles but they just dont give me the output what I want above. Ther eis one at:
http://blog.stevex.net/c-string-formatting-faq/
Any help would be greatly appreciated. Thank you.
-
October 29th, 2010, 04:57 PM
#2
Re: Currency formatting
Note: Using
Double dVal = Double.Parse(strValue).ToString("N");
gives a pretty decent formatted output. How can I use () to show -ve values I would like to show 3 decimal places. Like 123.4567 as 123.457.
Using the "N" formats it to 2 decimal places.
-
October 29th, 2010, 05:57 PM
#3
Re: Currency formatting
decimal rounded = decimal.Round( Argument, Digits );
http://msdn.microsoft.com/en-us/libr...nd(VS.71).aspx
-
October 31st, 2010, 02:05 AM
#4
Re: Currency formatting
 Originally Posted by CuteAssistant
Note: Using
Double dVal = Double.Parse(strValue).ToString("N");
gives a pretty decent formatted output. How can I use () to show -ve values I would like to show 3 decimal places. Like 123.4567 as 123.457.
Using the "N" formats it to 2 decimal places.
Read up on the "N" formatter here:
http://msdn.microsoft.com/en-us/libr...#NFormatString
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|