473,505 Members | 13,823 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

format numeric to string - decimal places

I have a Decimal or a Double - your choice. I'd like to print the number as
string with a specified number of decimal places. Let's say my number
110.5, and I'd like to capture it in a string with 3 decimal places:
"110.500". How do you do this? My method below isn't working so hot.

Decimal dcTotal = 110.5;
string strMyString = (Decimal.Round(dcTotal, 3)).ToString();
//Do something with this string

Thanks in advance!

Mark
Nov 15 '05 #1
3 14816
Console.WriteLine("Number Formatting - {0:F3}", 111.5555);

--

This posting is provided "AS IS" with no warranties, and confers no rights.
"Mark" <fi**************@umn.edu> wrote in message
news:uq**************@TK2MSFTNGP12.phx.gbl...
I have a Decimal or a Double - your choice. I'd like to print the number as string with a specified number of decimal places.

Nov 15 '05 #2
Mark wrote:
I have a Decimal or a Double - your choice. I'd like to print the number as
string with a specified number of decimal places. Let's say my number
110.5, and I'd like to capture it in a string with 3 decimal places:
"110.500". How do you do this? My method below isn't working so hot.

Decimal dcTotal = 110.5;
string strMyString = (Decimal.Round(dcTotal, 3)).ToString();
//Do something with this string


dcTotal.ToString("0.000")

To be honest, I find it difficult to locate this information in the docs
- it takes a bit of digging past relatively useless stuff about
NumberFormatInfo and CultureInfo classes to get to the basic, predefined
format characters I want.

This information happens to be in the docs under the heading "Custom
Numeric Format Strings".

Note to MS: please put links to the standard and custom formatting
characters for the numeric and DataTime types in the document pages for
ToString() and String.Format().
--
mikeb
Nov 15 '05 #3

"> > I have a Decimal or a Double - your choice. I'd like to print the
number as
....
To be honest, I find it difficult to locate this information in the docs

I agree on that.
Nov 15 '05 #4

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

Similar topics

2
15854
by: Bubba | last post by:
I know it's possible, just don't know how to do it. I have a spreadsheet that I imported into access. Two of the columns in the table have Hard Drive space values listed for example 2.45 GB and 453...
1
2518
by: MAF | last post by:
How can I set the number of decimal places for a double value?
4
9443
by: Phil Mc | last post by:
OK this should be bread and butter, easy to do, but I seem to be going around in circles and not getting any answer to achieving this simple task. I have numbers in string format (they are...
2
6967
by: hunslair | last post by:
This is a really basic question. I am taking a teach yourself beginners course on Access 2003 and have run into a road block on one practice. In a select query, I have created a simple calculation...
17
5256
by: scan87 | last post by:
Can somone please, please give me the solution for the following problem. I need to submit it on Monday. Write a global function called format, which formats numbers with a given number of decimal...
3
1688
by: Andrus | last post by:
I have lot of columns in database like Price Numeric(5,2) Street Character(30) For UI display and validation I need to retrieve width and for numeric properties, decimal places of ...
3
1976
by: David | last post by:
Any ideas why this statement: mBalanceChange = Double.Parse(strCurrentBalance, Globalization.NumberStyles.AllowThousands Or Globalization.NumberStyles.AllowDecimalPoint) - mBalanceDouble ...
4
2767
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I format a Number as a String with exactly 2 decimal places?...
8
5362
NeoPa
by: NeoPa | last post by:
I have noticed this over many versions of Access and was wondering if anyone could throw any light on why this seems to happen. It seems that when designing a QueryDef in the QBE grid and...
0
7213
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
7098
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
7298
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,...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5026
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
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
406
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.