Formatting a number without rounding

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
 
K

Karl Seguin

*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
 
K

Karl Seguin

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top