Click here to Skip to main content
15,042,336 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi , I have a webapp that determines certain activities via selections made. The text boxes are populated with a QueryString .


The problem i am facing is that i need to format the amount that is given to me. In the example above "Amtv=00000000000008700" needs to be displayed as 87.00 in the textbox.

The code below is what i have but it is not working. Any help would be appreciated.

String Amtv = Request.QueryString["Amtv"];
txtboxAmount.Text = string.Format("{0:#.##}", Convert.ToInt64(Amtv));  
Updated 18-Oct-11 20:00pm
Please remove irrelevant tags "ASP.NET" and "WebForms".

Why don't you use a simple approach?

String Amtv = "00000000000008700";
int iTemp = Convert.ToInt32(Amtv); // Remove the leading zeros
Amtv = Convert.ToString(iTemp); // Convert back to a string
Amtv = Amtv.Insert(Amtv.Length - 2, "."); // Insert the decimal point
Rico_ 19-Oct-11 2:07am
thanks for your suggestion.
CodingLover 19-Oct-11 2:42am
You are welcome!
Before passing to string.Format, you need to divide your 64-bit number by 100. And the format string is wrong, of course.


You can use either standard or custom formatting, depending on your requirements which you did not share. One example is not enough. What's the valid range of numbers? Do you want zero-padding (than you would use "00.00")? Can it be more than 100 or 1000, etc.? In this case "##.##" will be not enough. Do you need fixed relative precision or absolute? Depending on that, I would simply use standard "F" (fixed-point) or "G" (general) format, but it all depends on detail of your requirements. Read the MSDN help articles referenced above, try it our accurately and choose what you really need. Don't forget to delete by 100. :-)

Rico_ 19-Oct-11 2:10am
thanks for your post.
You are welcome.
You can use (Convert.ToInt64(Amtv) / 100).ToString("F") or string.Format("{0:F}", Convert.ToInt64(Amtv)/100) as,

txtboxAmount.Text = string.Format("{0:F}", Convert.ToInt64(Amtv)/100);

*You forgot to divide by hundred.
Rico_ 19-Oct-11 2:06am
thanks. this worked well for me
Right, my 5. Exact format depends on exact requirements, as I tried to explain in my solution, please see.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900