Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - Convert Formatted Double Into String

Reply
 
Old 07-06-2008   #1 (permalink)
Derek Hart


 
 

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



My System SpecsSystem Spec
Old 07-07-2008   #2 (permalink)
Armin Zingler


 
 

Re: Convert Formatted Double Into String

"Derek Hart" <derekmhart@xxxxxx> schrieb
Quote:

> 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

My System SpecsSystem Spec
Old 07-07-2008   #3 (permalink)
Jeff Winn


 
 

Re: Convert Formatted Double Into String

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:
Quote:

> "Derek Hart" <derekmhart@xxxxxx> schrieb
Quote:

> > 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
>
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Convert Byte() to string VB Script
Convert to & from base64 String PowerShell
convert int to numeric (formatted) string .NET General
convert array of strings to string PowerShell
here-string with single and double quotes PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46