473,382 Members | 1,349 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How to convert decimal to string ?

How do I convert a decimal to string, in a way so that only 4 digits after
the dot is present . E.G like in the below table:

Value : writeln
3.234556 : 3.2346 (or maybe just 3.2345)
0.34 : 0.3400
0.112234 : 0.1122

Best Regards,

Anders Both, Denmark.
Nov 15 '05 #1
2 36110
Anders,

Have a look at "Custom Numeric Format Strings" in MSDN online help.

Here is a quick hack that seems to get what you are looking for:
/* *************************** */
static void Main(string[] args) {
System.Console.WriteLine("String : {0}",(39.12346D).ToString("0.0000"));
System.Console.WriteLine("String : {0}",(0.34D).ToString("0.0000"));
System.Console.WriteLine("String : {0}",(0.112234D).ToString("0.0000"));
}
/* *************************** */

and the output is:

String : 39.1235
String : 0.3400
String : 0.1122
regards
roy fine

"Anders Both" <an********@hotmail.com> wrote in message
news:O8**************@TK2MSFTNGP09.phx.gbl...
How do I convert a decimal to string, in a way so that only 4 digits after
the dot is present . E.G like in the below table:

Value : writeln
3.234556 : 3.2346 (or maybe just 3.2345)
0.34 : 0.3400
0.112234 : 0.1122

Best Regards,

Anders Both, Denmark.

Nov 15 '05 #2

Thx, alot.
"Roy Fine" <rl****@twt.obfuscate.net> wrote in message
news:Ol**************@TK2MSFTNGP09.phx.gbl...
Anders,

Have a look at "Custom Numeric Format Strings" in MSDN online help.

Here is a quick hack that seems to get what you are looking for:
/* *************************** */
static void Main(string[] args) {
System.Console.WriteLine("String : {0}",(39.12346D).ToString("0.0000"));
System.Console.WriteLine("String : {0}",(0.34D).ToString("0.0000"));
System.Console.WriteLine("String : {0}",(0.112234D).ToString("0.0000"));
}
/* *************************** */

and the output is:

String : 39.1235
String : 0.3400
String : 0.1122
regards
roy fine

"Anders Both" <an********@hotmail.com> wrote in message
news:O8**************@TK2MSFTNGP09.phx.gbl...
How do I convert a decimal to string, in a way so that only 4 digits after the dot is present . E.G like in the below table:

Value : writeln
3.234556 : 3.2346 (or maybe just 3.2345)
0.34 : 0.3400
0.112234 : 0.1122

Best Regards,

Anders Both, Denmark.


Nov 15 '05 #3

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

Similar topics

2
by: Krish | last post by:
Hi, How to convert "1283912839E-5" string (in scientific format) to a decimal. Convert.ToDecimal("1283912839E-5") is throwing "Input string is not in correct format" exception. Is the...
4
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a...
2
by: KB | last post by:
Hi guys, In my DataGrid I have a column that displays decimal values as currency ( I set the Data Formatting expression of that column to {0:C}). So the actual string displayed in the grid looks...
3
by: JenHu | last post by:
Hi all, I have to read from a text file and generate values and insert to database. But first of all, when the text file contains '0000000000', I received a sEfundAmt value = 0D instead of 0.0...
7
by: patang | last post by:
I want to convert amount to words. Is there any funciton available? Example: $230.30 Two Hundred Thirty Dollars and 30/100
6
by: patang | last post by:
Could someone please tell me where am I supposed to put this code. Actually my project has two forms. I created a new module and have put the following code sent by someone. All the function...
7
by: elliotng.ee | last post by:
I have a text file that contains a header 32-bit binary. For example, the text file could be: %%This is the input text %%test.txt Date: Tue Dec 26 14:03:35 2006...
6
by: Mark Chimes | last post by:
Hi All, I need to search thru some strings and discard them if they canot be converted to a decimal or interger value. What is the best way to do this? cheers, Mark Chimes
19
by: VK | last post by:
http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/ b495b4898808fde0> is more than one month old - this may pose problem for posting over some news servers. This is why I'm...
10
by: cmdolcet69 | last post by:
Public ArrList As New ArrayList Public bitvalue As Byte() Public Sub addvalues() Dim index As Integer ArrList.Add(100) ArrList.Add(200) ArrList.Add(300) ArrList.Add(400) ArrList.Add(500)
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.