Cast, Int

Bitwise Divide

(double)100 / 345 = ...
100 / (double)345 = ...

double

using System;
*// Divide the first number by the second number.*
int operand1 = 100;
int operand2 = 345;
*// Incorrect division for double:*
double number1 = operand1 / operand2;
Console.WriteLine(number1);
*// Correct division for double:*
double number2 = (double)operand1 / operand2;
Console.WriteLine(number2);
*// Incorrect division for double:*
double number3 = (double)(operand1 / operand2);
Console.WriteLine(number3);
*// Correct division for double:*
double number4 = (double)operand1 / (double)operand2;
Console.WriteLine(number4);
*// Correct division for double:*
double number5 = operand1 / (double)operand2;
Console.WriteLine(number5);0
0.289855072463768
0
0.289855072463768
0.289855072463768

Modulo

Dot Net Perls is a collection of tested code examples. Pages are continually updated to stay current, with code correctness a top priority.

Sam Allen is passionate about computer languages. In the past, his work has been recommended by Apple and Microsoft and he has studied computers at a selective university in the United States.

This page was last updated on Sep 7, 2023 (edit).