OCDProgrammer.com

It's Microsoft's World, and I'm just living in it
View Clarence Klopfstein's profile on LinkedIn

Clarence Klopfstein's Facebook profile

This site is under construction...

Categories

New Comments

Referring Sites


Disclaimer

  • This is MY blog. The views represented here are not in relation to anybody else. Please read my full disclaimer for a more complete disclaimer.

Math with Doubles and Decimals in .NET

June 28, 2008 03:00 by ckincincy

Just before I went on vacation I had an interesting issue at work.

I was trying to multiple an int by a decimal.  Nothing big, but I kept getting this error:

Operator '*' cannot be applied to operands of type 'decimal'

I was floored, what do you mean I can't multiply a decimal in .NET?  What in the world are you talking about?

So after a brief search I found the fix.

Basically I had to add an M to the decimal.  So instead of:

4 * .95

I needed:

4 * .95M

Honestly still don't understand WHY Microsoft would think this is required, but they do. 

Hope this helps you as it helped me.

HT: Asp.net


Comments are closed