Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why use Decimal.Multiply vs operator multiply?

Tags:

c#

math

decimal result = 100 * 200; 

vs

decimal result = Decimal.Multiply(100, 200); 
like image 930
O.O Avatar asked Mar 21 '11 20:03

O.O


People also ask

What operation is used in multiplying decimals?

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.

Why is multiplying decimals important?

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.

What is the most important thing when multiplying decimals?

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.

What does multiplying by a decimal mean?

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.


1 Answers

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.

like image 124
Kelsey Avatar answered Sep 23 '22 20:09

Kelsey