Formatting a number without rounding

  • Thread starter Thread starter Thor W Hammer
  • Start date Start date
T

Thor W Hammer

How can we format a decimal variable so that it has two decimal digits but
not rounding it. Like this:
Original value: 5.225;
Output: 2.22; and NOT 2.23
 
*shrug* an annoyance to be sure :) There's no built-in method. Math.Floor
works on integers. Math.Round does banker's rounding. All the formatters
will automatically round.

Personally, i'd just turn it into a string and chop it up!

Karl
 
Uhmm..here's a better one, multiple by 100, floor it, and divide by 100 :)

decimal d = 101.328m;
Math.Floor(((double)d*100))/100;

Karl
 

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

Back
Top