PositiveGuy
PositiveGuy

Reputation: 47743

How can I compare a decimal with a hardcoded value?

Never needed to do this before till now.

trying to make sure the chargeAmount (which is type decimal) does not go below 1 cent:

 if (chargeAmount < 0.01)
                throw new ArgumentOutOfRangeException("chargeAmount");

I tried 0.01D but obviously I am not sure how you format this.

Upvotes: 2

Views: 3489

Answers (2)

Oded
Oded

Reputation: 499002

A decimal literal does not use D (that's for Double) - it uses M (for Money):

if (chargeAmount < 0.01M)
  throw new ArgumentOutOfRangeException("chargeAmount");

Upvotes: 3

Jon Hanna
Jon Hanna

Reputation: 113272

You mean you want it to be a decimal literal rather than double?

if (chargeAmount < 0.01m)

Upvotes: 12

Related Questions