467,886 Members | 1,807 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,886 developers. It's quick & easy.

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
  • viewed: 1106
Share:
2 Replies
"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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Marty | last post: by
6 posts views Thread by JKop | last post: by
17 posts views Thread by David Scemama | last post: by
5 posts views Thread by nbohana | last post: by
2 posts views Thread by phil.swenson | last post: by
2 posts views Thread by Derek Hart | last post: by
3 posts views Thread by =?Utf-8?B?U2hlbGRvbg==?= | last post: by
reply views Thread by MrMoon | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.