Operations with Decimals

Tango.CommonOperations.DecimalOperations

This static class contains methods and properties to expose common operations to work with decimal types.

All members bellow returns the corresponding functions as delegates.

WARNING

All operations classes related to numerical values (int, decimal e double) contains the same properties and methods.

Properties

Name

Type

Description

Add

Func<decimal, decimal, decimal>

Function to represents addition operation (+) between two values.

Subtract

Func<decimal, decimal, decimal>

Function to represents subtraction operation (-) between two values.

Multiply

Func<decimal, decimal, decimal>

Function to represents multiplication operation (*) between two values.

Divide

Func<decimal, decimal, decimal>

Function to represents division operation (/) between two values.

Add3

Func<decimal, decimal, decimal, decimal>

Function to represents addition operation (+) between three values.

Subtract3

Func<decimal, decimal, decimal, decimal>

Function to represents subtraction operation (-) between three values.

Multiply3

Func<decimal, decimal, decimal, decimal>

Function to represents multiplication operation (*) between three values.

Divide3

Func<decimal, decimal, decimal, decimal>

Function to represents division operation (/) between three values.

Methods

Name

Parameters

Returns

Description

AddWith

decimal value

Func<decimal, decimal>

Function to represents addition operation (+) between two values, applying first value as partial application on Add method.

SubtractWith

decimal value

Func<decimal, decimal>

Function to represents subtraction operation (-) between two values, applying first value as partial application on Subtract method.

MultiplyWith

decimal value

Func<decimal, decimal>

Function to represents multiplication operation (*) between two values, applying first value as partial application on Multiply method.

DivideWith

decimal value

Func<decimal, decimal>

Function to represents multiplication operation (/) between two values, applying first value as partial application on Divide method.

Add3With

decimal value

Func<decimal, decimal, decimal>

Function to represents addition operation (+) between three values, applying first value as partial application on Add3 method.

Add3With

decimal value

decimal value2

Func<decimal, decimal>

Function to represents addition operation (+) between three values, applying first and second values as partial application on Add3 method.

Subtract3With

decimal value

Func<decimal, decimal, decimal>

Function to represents subtraction operation (-) between three values, applying first value as partial application on Subtract3 method.

Subtract3With

decimal value

decimal value2

Func<decimal, decimal>

Function to represents subtraction operation (-) between three values, applying first and second values as partial application on Subtract3 method.

Multiply3With

decimal value

Func<decimal, decimal, decimal>

Function to represents multiplication operation (*) between three values, applying first value as partial application on Multiply3 method.

Multiply3With

decimal value

decimal value2

Func<decimal, decimal>

Function to represents multiplication operation (*) between three values, applying first and second values as partial application on Multiply3 method.

Divide3With

decimal value

Func<decimal, decimal, decimal>

Function to represents division operation (/) between three values, applying first value as partial application on Divide3 method.

Divide3With

decimal value

decimal value2

Func<decimal, decimal>

Function to represents division operation (/) between three values, applying first and second values as partial application on Divide3 method.

Usage

The properties returns a delegate, so, it's possible to use it as a method.

Add

decimal value = 10;
decimal value2 = 5;
decimal result = DecimalOperations.Add(value, value2);

//result= 15

Subtract

decimal value = 10;
decimal value2 = 5;
decimal result = DecimalOperations.Subtract(value, value2);

//result= 5

Multiply

decimal value = 10;
decimal value2 = 5;
decimal result = DecimalOperations.Multiply(value, value2);

//result= 50

Divide

decimal value = 10;
decimal value2 = 5;
decimal result = DecimalOperations.Divide(value, value2);

//result= 2

For methods you can use a little different sintax. It's necessary because these methods uses the property methods combined with Partial Application.

Because of that, you need to execute the method with the first parameter to creates a new single parameter function that perform the operation.

AddWith

decimal value = 10;
decimal value2 = 5;
Func<decimal,decimal> addWith= DecimalOperations.AddWith(value);
decimal result = addWith(value2);

//result= 15

You can also use it as a chainable operation:

decimal value = 10;
decimal value2 = 5;
decimal result = DecimalOperations.AddWith(value)(value2);

//result= 15

The ~With operations are available to the four main operations, all of them follows the same caracteristics that the previous example.

You can use these methods as Partial Applications if you needs to.

Add3With

decimal value = 10;
decimal value2 = 5;
decimal value3 = 5
Func<decimal, decimal, decimal> addWith2= DecimalOperations.Add3With(value);
decimal result = addWith2(value2, value3);

//result= 20

You can also use it as a chainable operation:

decimal value = 10;
decimal value2 = 5;
decimal value3 = 5
decimal result = DecimalOperations.Add3With(value)(value2, value3);

//result= 20

You can use the two parameters overload as well:

decimal value = 10;
decimal value2 = 5;
decimal value3 = 5
Func<decimal, decimal> addWith= DecimalOperations.Add3With(value, value2);
decimal result = addWith(value3);

//result= 20
decimal value = 10;
decimal value2 = 5;
decimal value3 = 5
decimal result = DecimalOperations.Add3With(value,value2)(value3);

//result= 20

Last updated