Formatting a decimal so that the result always has two decimal places

The following vb.net statement calculates the payment as amount * rate.

PAYMENT.Text = "$" + Convert.ToString(Convert.ToDecimal(Convert.ToDouble(AMOUNT.Text) * Convert.ToDecimal(RATE.Text)))

and payment does not always have two trailing decimals.

I want to format payment as a currency e.g. $30.00 or $32.12.

How can I modify my statement to achieve that?
sib_userAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

silemoneCommented:
Payment.Text = "$"
Payment.Text += (Convert.ToString(Convert.ToDecimal(Convert.ToDouble(AMOUNT.Text) * Convert.ToDecimal(RATE.Text)))).ToString("N:2")...

0
sib_userAuthor Commented:
silemone,
When I try your solution, I get the error:
Unable to cast object of type 'System.String' to type 'System.IFormatProvider'.
0
Alfred A.Commented:
Try this,

PAYMENT.Text = Convert.ToDecimal(Convert.ToDouble(AMOUNT.Text) * Convert.ToDecimal(RATE.Text)).ToString("C2")

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

Alfred A.Commented:
Or, you can try the following

PAYMENT.Text = String.Format("{0:C2}",Convert.ToDecimal(Convert.ToDouble(AMOUNT.Text) * Convert.ToDecimal(RATE.Text)));
PAYMENT.Text = String.Format("{0:$#.##}",Convert.ToDecimal(Convert.ToDouble(AMOUNT.Text) * Convert.ToDecimal(RATE.Text)));
PAYMENT.Text = String.Format("{0:$#.00}",Convert.ToDecimal(Convert.ToDouble(AMOUNT.Text) * Convert.ToDecimal(RATE.Text)));
0
drypzCommented:
Hi! Like this

PAYMENT.Text = String.Format("{0:N2}", Convert.ToDecimal(AMOUNT.Text) * Convert.ToDecimal(RATE.Text))
0
sib_userAuthor Commented:
Thanks to all for so many choices.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.