hi there,

can some one explain what is happening the below code:

if (amt == "0.0000")
                    txtPAmt.Text = "";
                    decimal d;
                    decimal.TryParse(amt, out d);
                    txtPAmt.Text = d.ToString("$0000000000.00");


What do you think is happening?

(I'm not being facetious, I just want to try and get you to think about it)

if u enter 1.23 it will be displayed as $0000000001.23

how does it work,


Ok, the "ToString" method can take a string argument to act as a formatter.

So for every "0" it means it expects a number, if no number is given, it will place a 0 there. If there is a number, the 0 is replaced with it. So your parameter is read as d.ToString("Create a number that is 10 digits long with two decimal places and overwrite it with the value I contain")

Edited 6 Years Ago by Ketsuekiame: n/a

I refrain from using C as it puts it in the local culture currency. It's very easy to forget to switch cultures ^^

I use #,##0.00 with the correct currency symbol for whichever currency it is.

Typically though, you are correct, and you should format with 'C' and the correct culture.

Edited 6 Years Ago by Ketsuekiame: n/a

Very well
This article has been dead for over six months. Start a new discussion instead.