I am fetching data from a web service. I am using ASP.NET and VB.NET as code behind.
I tried like this:
Label_amount.Text = Trim(arData(11))
I am getting the output as 0020000, while I should get 200, i.e. suppress all leading zeros and delete last two zeros. (or make as 200.00)
As others have said, if it is displaying as “0020000”, that must mean that
arData(11)is aString. If it’s supposed to always be a numeric value, it would be best to parse it into a numeric data type, such asIntegerorDecimal. Once you have the value stored as a numeric type, you can easily manipulate it (such as dividing by 100) and format it as desired. For instance:Keep in mind that the
Parsemethod will throw an exception ifarData(11)does not contain a valid numeric value, so you may want to wrap it with a try/catch, or use theTryParsemethod instead, depending on your needs.ToString("N2")will return “200.00”,ToString()will return “200”, andToString("C")will return “$200.00” (in the US).