Format Currency driving me nuts!!!!

R

rlueneberg

I am having trouble with properly formating decimal numbers.

Look:
decimal NewPrice = 0;
NewPrice = Convert.ToDecimal(Price) * Convert.ToInt32(item.Quantity);

For example, for the decimal value of 1800.00 I get the folowing
results:

without formating
1800.00

with formating
NewPrice.ToString("$#,##0.00")
$1,800.00,800.00

If I change the value to 600, it works?????


Rod
 
K

Ken Cox [Microsoft MVP]

Hey Rod,

Not sure where you're going wrong, but try this?

System.Threading.Thread.CurrentThread.CurrentCulture =
new System.Globalization.CultureInfo("en-us");
decimal NewPrice;
double Price= 54.51;
Int32 Quantity=32;
NewPrice = Convert.ToDecimal(Convert.ToDecimal(Price) *
Convert.ToInt32(Quantity));
Label1.Text=NewPrice.ToString("C");

Ken
Microsoft MVP [ASP.NET]
 
R

rlueneberg

Thanks Ken,

I will try it this weekend. Do you knows the difference between the
convert.ToDecimal and the parse.decimal ?

Rod

BTW, here's the reference for the standard numeric format strings:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgu...

Ken
Microsoft MVP [ASP.NET]

I am having trouble with properly formating decimal numbers.
Look:
decimal NewPrice = 0;
NewPrice = Convert.ToDecimal(Price) * Convert.ToInt32(item.Quantity);
For example, for the decimal value of 1800.00 I get the folowing
results:
without formating
1800.00
with formating
NewPrice.ToString("$#,##0.00")
$1,800.00,800.00
If I change the value to 600, it works?????
 

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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,152
Latest member
LorettaGur
Top