decimal result = 100 * 200;
vs
decimal result = Decimal.Multiply(100, 200);
To multiply decimals, first multiply as if there is no decimal. Next, count the number of digits after the decimal in each factor. Finally, put the same number of digits behind the decimal in the product.
Rule for multiplying decimals A common way to multiply decimals is to treat them as whole numbers, and then position the decimal point in the product. The number of digits after the decimal points in the factors determines where the decimal point is placed in the answer. For example, 0.3 x 0.8 = 0.24.
The process for multiplying decimals is the same as for multiplying whole integers. The decimal point must be put in the product so that the total number of decimal places equals the sum of decimal places in all multiplicands and multipliers.
Multiplying Two Decimal Numbers Step 1: Multiply the two numbers as two whole numbers. Thus, 36 × 13 = 468. Step 2: Now, there is one digit each after the decimal point in the factors. So, the product will have 1 + 1 = 2 digits after the decimal point. Therefore, 3.6 × 1.3 = 4.68.
Using the Decimal.Multiply
will force the multiply to take inputs of type decimal
instead of whatever the type that is being used and converted to decimal
.
Decimal.Multiply(decimal d1, decimal d2)
and will enforce and output of type decimal
. Where as the *
you could do:
decimal result = yourDecimal * yourInt;
This allows you to mix and match types in some cases and it will handle it all for you but the type is not guaranteed to be decimal depending on how the right side is defined.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With