How do I limit a value to 2 decimal places?

  • Thread starter Thread starter JamesL
  • Start date Start date
J

JamesL

Kind of a silly little one for me to be stumped on but:

I do some math on some values that represent money. The math may result in
several decimal places but since it is money I only want to display 2
decimal places on the screen and store 2 decimal places in my text file.
How do I limit the value to 2 decimal places.

This is usually pretty simple but I am stumped. Am I overlooking the
obvious on this one?

James Lysaght
 
I haven't had need to use this in CF, but in the full framework, you simply
do it like so:

SalePrice = Math.Round(yourDecimalValue, 2)
 
Try this:

decimal d = 123.4567m;
d.ToString("0.00");

or

Math.Round(d, 2).ToString();

or

String.Format("{0:0.00}", d)
 
Back
Top