473,474 Members | 1,348 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Format Numbers?

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
Nov 18 '05 #1
3 1282
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/de...ttingtypes.asp

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

"Keith" <kc****@hotmail.com> wrote in message
news:Om**************@tk2msftngp13.phx.gbl...
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
Nov 18 '05 #2
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.

"Keith" <kc****@hotmail.com> wrote in message
news:Om**************@tk2msftngp13.phx.gbl...
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
Nov 18 '05 #3
Great! Thanks for all the input.

Keith

"Kevin Spencer" <ke***@takempis.com> wrote in message
news:ed*************@TK2MSFTNGP12.phx.gbl...
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.

"Keith" <kc****@hotmail.com> wrote in message
news:Om**************@tk2msftngp13.phx.gbl...
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

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Rookie | last post by:
I need to display several columns of numbers in a textbox. I wish to display the columns with the decimal point position aligned vertically. I have found that the # digit placeholders do not...
0
by: Rob | last post by:
Hi all, I want to format right-aligned positive and negative numbers in a grid. My problem is that I want the negs in parentheses, which is throwing out the alignment. For example, using the...
1
by: Mike MacSween | last post by:
This looks like a bug to me. I have an expression on a report: =Format(Sum((**)*(/)),"0.00") Score is byte PercentOfGrade is double PropDegree is single ModuleCats is byte
5
by: Ataru Morooka | last post by:
Hi, my table has to have a column with the months names (january, february...). When I order it by month it is ordered alphabetically and that's not what I need. Reading this ng I found someone...
5
by: Subrahmanyam Arya | last post by:
Hi Folks , I am trying to solve the problem of reading the numbers correctly from a serial line into an intel pentium processor machine . I am reading 1 byte and 2byte data both positive...
5
by: Fabian | last post by:
I am making a winforms-program in Visual Studio, that connects to an Access database. In the database all dates are presented in this format : dd-mm-yyyy. In my application I have a DatetimePicker,...
8
by: John Brock | last post by:
I am creating an Excel workbook using VB.NET, and have run into a problem. Excel at times insists on reformatting data that I enter into cells, e.g., converting "01234" to "1234", and this screws...
2
by: gjuro kladaric | last post by:
hi there, I am just learning about IFormattable, ICustomFormatter, IFormatProvider and the like... although being a bit tricky to understand, it becomes clear after some clicking and...
6
by: psbasha | last post by:
I have a input format XX:YY:ZZ and the start value may be 'n' digit numbers for X,Y,Z. So I have to assign the numbers based on the above format ( Format may change) Say Example - 1 ...
7
by: pamela fluente | last post by:
My numericUpDowns show numbers in the format 1.500,56 (italy). Instead, I need *invariantly* that they show and accept the format 1,500.56, as in the USA. What's the right way to do that? I...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.