From: Derek Hart on
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


From: Armin Zingler on
"Derek Hart" <derekmhart(a)yahoo.com> schrieb
> 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

From: Jeff Winn on
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" <derekmhart(a)yahoo.com> schrieb
> > 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
>
>
 | 
Pages: 1
Prev: clr and jit
Next: date time formatting