If we divide an integer by another integer, the result in C# is always an integer. How can we make the result to be 2 decimal? For example: 77 / 21 = 3.67 Thanks.

Please mark this post as "Answer" and earn a point.

Thanks, that's what I found too. But the decimal needs to be formatted to 2 decimal. Otherwise it would show as a long bunch of decimals. Specifically how do we format a long decimal to "999.99" in C#? (We know how to do it in VB) Thanks.

Please mark this post as "Answer" and earn a point.

"you *could* always overload the \ operator" Overloads are attached to types, though. You can only overload operators on types that you control! Jim
ThoughtWorks

"how do we format a long decimal to "999.99"" Use the ToString() overload with a format specifier. Something like (off the top of my head): myDecimal.ToString("#.00"); Jim
ThoughtWorks

::Overloads are attached to types, though. You can only overload operators on types that you control! Jim, you're right, but you can control the output. you can return a different type. you can always overload the / for int,int to return a decimal type, and
do the casting in the overloaded operator.

Jim, I didn't say it's going to be easy. Or that it was a good solution. I just said it was "possible". Just create an object that is essentially a decimal, and start creating a crapload of overloaded operators. Now. I'll admit that the original post was done
in bad taste for humor, but still. It "is" possible. I'd be the first to slap someone that wanted to do it like that, but that wasn't the purpose of my initial post here.

## thuhue

All-Star

15635 Points

3146 Posts

## How to divide an integer by an integer and yield a decimal

Aug 25, 2004 01:35 AM|thuhue|LINK

markthis post as "Answer" and earn a point.## jimski3000

Participant

1550 Points

304 Posts

## Re: How to divide an integer by an integer and yield a decimal

Aug 25, 2004 11:16 AM|jimski3000|LINK

## thuhue

All-Star

15635 Points

3146 Posts

## Re: How to divide an integer by an integer and yield a decimal

Aug 25, 2004 05:18 PM|thuhue|LINK

markthis post as "Answer" and earn a point.## KraGiE

Star

14567 Points

2926 Posts

## Re: How to divide an integer by an integer and yield a decimal

Aug 25, 2004 09:28 PM|KraGiE|LINK

## jimski3000

Participant

1550 Points

304 Posts

## Re: How to divide an integer by an integer and yield a decimal

Aug 25, 2004 09:59 PM|jimski3000|LINK

## jimski3000

Participant

1550 Points

304 Posts

## Re: How to divide an integer by an integer and yield a decimal

Aug 25, 2004 10:01 PM|jimski3000|LINK

## imleggy

Contributor

2680 Points

536 Posts

## Re: How to divide an integer by an integer and yield a decimal

Aug 27, 2004 08:43 AM|imleggy|LINK

## thuhue

All-Star

15635 Points

3146 Posts

## Re: How to divide an integer by an integer and yield a decimal

Aug 27, 2004 09:26 PM|thuhue|LINK

markthis post as "Answer" and earn a point.## pickyh3d

Star

9696 Points

1955 Posts

## Re: How to divide an integer by an integer and yield a decimal

Aug 29, 2004 08:13 AM|pickyh3d|LINK

## thuhue

All-Star

15635 Points

3146 Posts

## Re: How to divide an integer by an integer and yield a decimal

Aug 29, 2004 09:35 PM|thuhue|LINK

markthis post as "Answer" and earn a point.## KraGiE

Star

14567 Points

2926 Posts

## Re: How to divide an integer by an integer and yield a decimal

Aug 29, 2004 10:46 PM|KraGiE|LINK

## pickyh3d

Star

9696 Points

1955 Posts

## Re: How to divide an integer by an integer and yield a decimal

Aug 30, 2004 01:15 AM|pickyh3d|LINK

## KraGiE

Star

14567 Points

2926 Posts

## Re: How to divide an integer by an integer and yield a decimal

Aug 30, 2004 07:03 AM|KraGiE|LINK

## jimski3000

Participant

1550 Points

304 Posts

## Re: How to divide an integer by an integer and yield a decimal

Aug 30, 2004 07:49 PM|jimski3000|LINK

## pickyh3d

Star

9696 Points

1955 Posts

## Re: How to divide an integer by an integer and yield a decimal

Aug 30, 2004 11:14 PM|pickyh3d|LINK

## KraGiE

Star

14567 Points

2926 Posts

## Re: How to divide an integer by an integer and yield a decimal

Aug 31, 2004 06:48 AM|KraGiE|LINK

## thuhue

All-Star

15635 Points

3146 Posts

## Re: How to divide an integer by an integer and yield a decimal

Aug 31, 2004 02:57 PM|thuhue|LINK

markthis post as "Answer" and earn a point.