By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,169 Members | 1,661 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,169 IT Pros & Developers. It's quick & easy.

Data Binding and formatting

P: n/a
Where can I find a fairly comprehensive list of the formatting codes used
when data binding. e.g. <%# Bind("Debit", "{0:C}") %>. Specifically
formatting a number to 2 decimal places. Regards, Chris.

Jul 7 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
use "{0:C2}" for 2 decimal places..

"Chris" <no****@btinternet.comwrote in message
news:ee**************@TK2MSFTNGP03.phx.gbl...
Where can I find a fairly comprehensive list of the formatting codes used
when data binding. e.g. <%# Bind("Debit", "{0:C}") %>. Specifically
formatting a number to 2 decimal places. Regards, Chris.

Jul 7 '06 #2

P: n/a
Chris,

Eval and Bind both use string.Format(). Here is a good reference for that:

http://msdn2.microsoft.com/en-us/library/fht0f5be.aspx

--

Andrew Robinson
http://blog.binaryocean.com
"Chris" <no****@btinternet.comwrote in message
news:ee**************@TK2MSFTNGP03.phx.gbl...
Where can I find a fairly comprehensive list of the formatting codes used
when data binding. e.g. <%# Bind("Debit", "{0:C}") %>. Specifically
formatting a number to 2 decimal places. Regards, Chris.

Jul 7 '06 #3

P: n/a
"{0:C2}" is for currency formats

when formatting a number to 2 decimal places, use

"{0:n2}"

http://authors.aspalliance.com/aspxt...atstrings.aspx

Jul 7 '06 #4

P: n/a

Winista wrote:
use "{0:C2}" for 2 decimal places..

"Chris" <no****@btinternet.comwrote in message
news:ee**************@TK2MSFTNGP03.phx.gbl...
Where can I find a fairly comprehensive list of the formatting codes used
when data binding. e.g. <%# Bind("Debit", "{0:C}") %>. Specifically
formatting a number to 2 decimal places. Regards, Chris.
On a related note, what does the "0" in {0:C2} indicate? I've seen
references to {1:xx} as well, though I've never seen it implemented.

Rich

Jul 8 '06 #5

P: n/a
Rich,

the 0 in {0:C2} is the placeholder for the variable you are formatting.

You could say:
double myMoney = 1;
double yourMoney = 2;
string foo = string.Format("My money is {0:C3}, and your money is
{1:C3}.", myMoney, yourMoney);

foo would be "My money is $1.000, and your money is $2.000.

Chris

Jul 8 '06 #6

P: n/a
chris wrote:
Rich,

the 0 in {0:C2} is the placeholder for the variable you are formatting.

You could say:
double myMoney = 1;
double yourMoney = 2;
string foo = string.Format("My money is {0:C3}, and your money is
{1:C3}.", myMoney, yourMoney);

foo would be "My money is $1.000, and your money is $2.000.
Thanks, chris. Out of curiosity, is that a known function from C or
something introduced with .Net? It looks familiar, but I don't recall
every encountering it in VB.

Rich

Jul 8 '06 #7

P: n/a
Not Sure Rich.

Jul 8 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.