Velocity Reviews > Formatting a number without rounding

# Formatting a number without rounding

Thor W Hammer
Guest
Posts: n/a

 11-22-2005
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
Guest
Posts: n/a

 11-22-2005
*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" <(E-Mail Removed)> wrote in message
news:43834bd5\$(E-Mail Removed)...
> 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
Guest
Posts: n/a

 11-22-2005
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" <(E-Mail Removed)> wrote in message
news:43834bd5\$(E-Mail Removed)...
> 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
>