472,780 Members | 1,383 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,780 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 1295
"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

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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.