hi there,

can some one explain what is happening the below code:

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

thankxxx

Recommended Answers

All 5 Replies

What do you think is happening?

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

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,

thankxx

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")

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.

commented: Very well +6
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.