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 .

"?AwdKey=2011-10-18-14.41.55.000007C01&AwdCrdattim=2011-10-18-14.41.55.000007&BusinessArea=IAM%20PP&WorkType=ADDFLOWGIB&EntityNo=411841&AccountNo=&IdNo=04110330589000&Name=KLINK&Amtv=00000000000008700&Team=VOLUNTARY&Regi=DBN&Intl=CL&Deal=&Brkc=200"

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.

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

Why don't you use a simple approach?

C#
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
   
v2
Comments
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.

See:
http://msdn.microsoft.com/en-us/library/txafckwd.aspx[^],
http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx[^],
http://msdn.microsoft.com/en-us/library/0c899ak8.aspx[^].

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. :-)

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

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

*You forgot to divide by hundred.
   
v2
Comments
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.
--SA

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