Format Numbers?

  • Thread starter Thread starter Keith
  • Start date Start date
K

Keith

Is there a way to trim the number of digits that are returned from a calculation? Currently the result is displayed in a label and looks like the number below:

0.733812949640288

I would like to just return 73 and then I could concatenate a % at the end.

I have tried the Trim function without any success. Any help is appreciated.

Thanks,
Keith
 
Hi,
String formatting is probably what you are looking for, something like:

Decimal d=0.733812949640288M;
Response.Write(String.Format("{0:0.##}%",d));

Here you'll find more details:

http://msdn.microsoft.com/library/d...y/en-us/cpguide/html/cpconformattingtypes.asp

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist

Is there a way to trim the number of digits that are returned from a
calculation? Currently the result is displayed in a label and looks like
the number below:

0.733812949640288

I would like to just return 73 and then I could concatenate a % at the end.

I have tried the Trim function without any success. Any help is
appreciated.

Thanks,
Keith
 
Hi Keith,

You can use the ToString() method, and pass a numeric format string to it.
Example:

Dim s As String
Dim d As Double = 0.733812949640288
s = d.ToString("0.00")

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

Is there a way to trim the number of digits that are returned from a
calculation? Currently the result is displayed in a label and looks like
the number below:

0.733812949640288

I would like to just return 73 and then I could concatenate a % at the end.

I have tried the Trim function without any success. Any help is
appreciated.

Thanks,
Keith
 
Back
Top