Formating currency on label

P

Paulo

Hi, I need to show on a label the data coming from db and it must show a
currency... I'm using a SqlDataReader reader, but doesnt work...

lblPreco.Text = Eval(reader[1].ToString(), "{0:c}");

Can you help me ? Thanks!

VS 2005 asp.net C# 2.0
 
G

George Ter-Saakov

"Show currency" is kind of vague....as "does not work"....I bet it works
just does not give you result you want :)

After you did reader[1].ToString() it becomes string and you can not apply
{0:c} to it. Since it only applicable to Decimal datatypes (numerics
probably too).

Not sure why you doing it that way

lblPreco.Text = reader.GetDecimal(1).ToString("c") should work...
Plus it's much faster ....

George.
 
P

Paulo

George, I found something on google:

lblPreco.Text = string.Format("{0:c}", reader[1]);

Thank you very much!

George Ter-Saakov said:
"Show currency" is kind of vague....as "does not work"....I bet it works
just does not give you result you want :)

After you did reader[1].ToString() it becomes string and you can not apply
{0:c} to it. Since it only applicable to Decimal datatypes (numerics
probably too).

Not sure why you doing it that way

lblPreco.Text = reader.GetDecimal(1).ToString("c") should work...
Plus it's much faster ....

George.


Paulo said:
Hi, I need to show on a label the data coming from db and it must show a
currency... I'm using a SqlDataReader reader, but doesnt work...

lblPreco.Text = Eval(reader[1].ToString(), "{0:c}");

Can you help me ? Thanks!

VS 2005 asp.net C# 2.0
 
S

sloan

Agreed.

You should always pick the granular "get".

..GetString()
..GetDateTime
..GetInt32()
etc, etc.

Instead of .GetValue() ... or how you're (mis) using the ToString().



George Ter-Saakov said:
"Show currency" is kind of vague....as "does not work"....I bet it works
just does not give you result you want :)

After you did reader[1].ToString() it becomes string and you can not apply
{0:c} to it. Since it only applicable to Decimal datatypes (numerics
probably too).

Not sure why you doing it that way

lblPreco.Text = reader.GetDecimal(1).ToString("c") should work...
Plus it's much faster ....

George.


Paulo said:
Hi, I need to show on a label the data coming from db and it must show a
currency... I'm using a SqlDataReader reader, but doesnt work...

lblPreco.Text = Eval(reader[1].ToString(), "{0:c}");

Can you help me ? Thanks!

VS 2005 asp.net C# 2.0
 
G

George Ter-Saakov

That is pretty much the same thing except slower :)

reader[1] returns an object that is actually has type Decimal.
Then you leave string.Format to figure it out and apply {0:c} accordingly.

with reader.GetDecimal(1).ToString("c") the guessing of which type reader[1]
is already done by you. Since GetDecimal returns Decimal.

George.


Paulo said:
George, I found something on google:

lblPreco.Text = string.Format("{0:c}", reader[1]);

Thank you very much!

George Ter-Saakov said:
"Show currency" is kind of vague....as "does not work"....I bet it works
just does not give you result you want :)

After you did reader[1].ToString() it becomes string and you can not
apply {0:c} to it. Since it only applicable to Decimal datatypes
(numerics probably too).

Not sure why you doing it that way

lblPreco.Text = reader.GetDecimal(1).ToString("c") should work...
Plus it's much faster ....

George.


Paulo said:
Hi, I need to show on a label the data coming from db and it must show a
currency... I'm using a SqlDataReader reader, but doesnt work...

lblPreco.Text = Eval(reader[1].ToString(), "{0:c}");

Can you help me ? Thanks!

VS 2005 asp.net C# 2.0
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,150
Latest member
MakersCBDReviews
Top