Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

decimal
remainder
c#
communitycreator

# What is Decimal.Remainder() in C#? Theodore Kelechukwu Onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

### Overview

In C#, Decimal.Remainder() is used to calculate the remainder after dividing two decimal values.

### Syntax

public static decimal Remainder (decimal d1, decimal d2);


### Parameters

d1: This is a mandatory decimal number. It is the dividend.

d2: This is also a mandatory decimal number. It is the divisor.

### Return value

A decimal value is returned, which is the remainder from the division of d1 by d2.

### Code

Run the code below to see the working of the remainder() method:

// use Systemusing System;// create classclass RemainderGetter{  // main method  static void Main()  {    // create decimal values    decimal d1 = 35.5m;    decimal d2 = 4.1m;    decimal d3 = 300.34m;    decimal d4 = 5.25m;    // get remainder    decimal r1 = Decimal.Remainder(d1, d2);    decimal r2 = Decimal.Remainder(d3, d4);    // print results    Console.WriteLine(r1);    Console.WriteLine(r2);  }}
Getting the remainder after dividing two decimal values

### Explanation

• Lines 11–14: We create several decimal numbers.

• Line 17: We call the Decimal.Remainder() method to get the remainder from the division of d1 by d2.

• Line 18: We use the Decimal.Remainder() method to get the remainder from the division of d3 by d4.

• Lines 21–22: We print the results to the console.

RELATED TAGS

decimal
remainder
c#
communitycreator

CONTRIBUTOR Theodore Kelechukwu Onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring

Learn in-demand tech skills in half the time 