Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format a string to a currency with negative currency like $(10.00)

I need to format a negative currency as follow: $(10.00)

I tried to use string.Format("{0:C}", itemprice) but that gives me this result ($10.00) (the $ inside the parenthesis

i also tried

string fmt = "##;(##)";
itemprice.ToString(fmt);

but it gives me the same as before ($10.00)

Any idea on how to get a result like this: $(10.00).

like image 779
Y2theZ Avatar asked Apr 26 '12 19:04

Y2theZ


1 Answers

itemPrice.ToString(@"$#,##0.00;$\(#,##0.00\)");

Should work. I just tested it on PowerShell:

PS C:\Users\Jcl> $teststring = "{0:$#,##0.00;$\(#,##0.00\)}"
PS C:\Users\Jcl> $teststring -f 2 
$2,00
PS C:\Users\Jcl> $teststring -f -2
$(2,00)

Is that what you want?

like image 191
Jcl Avatar answered Sep 20 '22 01:09

Jcl