# Formatting a number without rounding

Discussion in 'ASP .Net' started by Thor W Hammer, Nov 22, 2005.

1. ### Thor W HammerGuest

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

Thor W Hammer, Nov 22, 2005

2. ### Karl SeguinGuest

*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
--
MY ASP.Net tutorials
http://www.openmymind.net/

"Thor W Hammer" <> wrote in message
news:43834bd5\$...
> 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
>

Karl Seguin, Nov 22, 2005

3. ### Karl SeguinGuest

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

--
MY ASP.Net tutorials
http://www.openmymind.net/

"Thor W Hammer" <> wrote in message
news:43834bd5\$...
> 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
>

Karl Seguin, Nov 22, 2005