Based on this thread decimal vs double!, decimal is always used for money. What is the proper way to define percent? like TaxPercent? If it's double then for calculating amount * 8% (double) you would have to cast it. What's the proper way to define percent value (ie tax) and what would the calculation be.
Asked
Active
Viewed 1,477 times
1 Answers
4
Use the 'm' suffix to specify a literal as a decimal. So it must be 0.08m to ensure a double doesn't creep into the calculation.
decimal tax = amount * 0.08m;
You'll find a list of valid suffix characters in this post.

Community
- 1
- 1

Hans Passant
- 922,412
- 146
- 1,693
- 2,536
-
lets say you had to assign tax value of 8 to a variable: decimal taxPercent = (8 / 100); tax would now be 0 which is incorrect – ShaneKm Nov 18 '15 at 14:33
-
1Don't write bad code, that's an integer division. You should now know to write `8m / 100m`. – Hans Passant Nov 18 '15 at 16:56