![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Decimal.Multiply() Method in C#
The Decimal.Add() method in C# is used to multiply two specified Decimal values.
Syntax
Following is the syntax −
public static decimal Multiply (decimal val1, decimal val2);
Above, va1 is the multiplicand, whereas val2 is the multiplier.
Example
Let us now see an example to implement the Decimal.Multiply() method −
using System; public class Demo { public static void Main(){ Decimal val1 = 3.45m; Decimal val2 = 2.35m; Console.WriteLine("Decimal 1 = "+val1); Console.WriteLine("Decimal 2 = "+val2); Decimal res = Decimal.Multiply(val1, val2); Console.WriteLine("Result (Multiplication) = "+res); } }
Output
This will produce the following output −
Decimal 1 = 3.45 Decimal 2 = 2.35 Result (Multiplication) = 8.1075
Example
Let us now see another example to implement the Decimal.Multiply() method −
using System; public class Demo { public static void Main(){ Decimal val1 = Decimal.MinValue; Decimal val2 = 1.21m; Console.WriteLine("Decimal 1 = "+val1); Console.WriteLine("Decimal 2 = "+val2); Decimal res = Decimal.Multiply(val1, val2); Console.WriteLine("Result (Multiplication) = "+res); } }
Output
This will produce the following output displaying exception that the value exceeded for decimal −
Decimal 1 = -79228162514264337593543950335 Decimal 2 = 1.21 Run-time exception (line 13): Value was either too large or too small for a Decimal. Stack Trace: [System.OverflowException: Value was either too large or too small for a Decimal.] at System.Decimal.FCallMultiply(Decimal& d1, Decimal& d2) at System.Decimal.Multiply(Decimal d1, Decimal d2) at Demo.Main() :line 13
Advertisements