Kyle Hartman
Kyle Hartman

Reputation: 13

Textbox formatting to Currency C#.Net

I can't find an answer that suits what I need. So I figured I could ask you guys for help.

I have a textbox that I want to show a currency value of $0.00 or whatever value they type ex: $1,331.13. I want it to change the format on the tab index event or is it done some other way in a property setting?

What should i put in the put in the event? I was thinking it would be something like this:

string.Format("{0:c}", txtPaymentOwed.Text);

What am I doing wrong? Any help suggested would be appreciated thanks.

Upvotes: 1

Views: 10822

Answers (1)

L.B
L.B

Reputation: 116098

I guess the problem is related with the type of object you pass to String.Format

var s1 = string.Format("{0:c}", 3); //$3.00
var s2 = string.Format("{0:c}", "3"); //3 

try with

var s = string.Format("{0:c}", Decimal.Parse(txtPaymentOwed.Text));

Upvotes: 3

Related Questions