473,396 Members | 1,893 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,396 software developers and data experts.

Convert Formatted Double Into String

I have a double stored in a DataTable: dt.Rows(i)(MergeFieldName)

I want to format this and store it into a string.

I have formatting stored in a database, such as "$#,##0.00"

How do I use this formatting, apply it to dt.Rows(i)(MergeFieldName), which
is a double, and then store it in a string?

So if the value of dt.Rows(i)(MergeFieldName) is 14,122.05. I would get
$14,122.05.

Derek
Jul 7 '08 #1
2 1415
"Derek Hart" <de********@yahoo.comschrieb
I have a double stored in a DataTable: dt.Rows(i)(MergeFieldName)

I want to format this and store it into a string.

I have formatting stored in a database, such as "$#,##0.00"

How do I use this formatting, apply it to
dt.Rows(i)(MergeFieldName), which is a double, and then store it in
a string?

So if the value of dt.Rows(i)(MergeFieldName) is 14,122.05. I would
get $14,122.05.

What's the format of the format? :) I guess it's one of these:
http://msdn.microsoft.com/en-us/library/427bttx3.aspx

Example:
dim fmt as string = "$#,##0.00"
dim s as string

s = directcast(dt.Rows(i)(MergeFieldName), double).ToString(fmt)
Armin

Jul 7 '08 #2
As long as the type you're trying to format is a numeric data type the
formatting will work just fine. However, if you're trying to take a string
type that contains numeric data you will need to parse it to the appropriate
type before you can format it.

Example A:
Dim s As String = "1234.44"
s.ToString("$#,##0.00")

Will not work.

Example B:
Dim d As Double = Double.Parse("1234.44")
d.ToString("$#,##0.00")

Will work properly.

"Armin Zingler" wrote:
"Derek Hart" <de********@yahoo.comschrieb
I have a double stored in a DataTable: dt.Rows(i)(MergeFieldName)

I want to format this and store it into a string.

I have formatting stored in a database, such as "$#,##0.00"

How do I use this formatting, apply it to
dt.Rows(i)(MergeFieldName), which is a double, and then store it in
a string?

So if the value of dt.Rows(i)(MergeFieldName) is 14,122.05. I would
get $14,122.05.


What's the format of the format? :) I guess it's one of these:
http://msdn.microsoft.com/en-us/library/427bttx3.aspx

Example:
dim fmt as string = "$#,##0.00"
dim s as string

s = directcast(dt.Rows(i)(MergeFieldName), double).ToString(fmt)
Armin

Jul 7 '08 #3

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

Similar topics

4
by: cindy liu | last post by:
Hi, In .Net, how to convert a string to a double? Thanks in advance! Cindy
6
by: Marty | last post by:
Hi, If I don't know that my (or any) windows 2k regional setting for the decimal symbol is the dot (".") and I want to do this: 1- Dim dblOutput As Double 2- Dim strInput As...
6
by: JKop | last post by:
What's the best method to use? I've searched the web a bit and all I've come up with is "sprintf". Also, for the converse, ie. string to double, is "atof" the way to go? Kind Regards, ...
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...
17
by: David Scemama | last post by:
Hi, I'm writing a program using VB.NET that needs to communicate with a DOS Pascal program than cannot be modified. The communication channel is through some file databases, and I have a huge...
5
by: nbohana | last post by:
I have tried several methods in converting my string data to an int. I am getting a message back 'Input string was not in a correct format' strSQL1 = "SELECT FROM WHERE = " +...
8
by: shiniskumar | last post by:
Ive got a double variable dTotal =5.037717235E7 i formatted it using deciFormat.format(dTotal) and got the String value of dTotal=50377172.35 now i have to pass this value as an argument to a...
2
by: phil.swenson | last post by:
I'm using Prototype.js and would like to convert the contents of an HTML table to JSON. Converting to an array first is fine too. Any thoughts on this? I haven't seen anyone do anything this.......
2
by: Derek Hart | last post by:
I have a double stored in a DataTable: dt.Rows(i)(MergeFieldName) I want to format this and store it into a string. I have formatting stored in a database, such as "$#,##0.00"
3
by: =?Utf-8?B?U2hlbGRvbg==?= | last post by:
Hello - I have various times formatted like 00:00:00, so for example, 01:32:05 would be one thirty-two with five milliseconds. I need to convert this into seconds (an integer). First of...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
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...
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,...

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.