Format Numbers?

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
 
T

Teemu Keiski

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
 
K

Kevin Spencer

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top