Show / Hide Table of Contents

Class DecimalExtensions

Extension methods for decimal.

Inheritance
object
DecimalExtensions
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: Sartorius.SAF.Extensions
Assembly: Sartorius.SAF.dll
Syntax
public static class DecimalExtensions

Methods

View Source

Normalize(decimal, short, MidpointRounding?)

Normalizes the specified value to the number of given numberOfDecimalPlaces.

Declaration
public static decimal Normalize(this decimal value, short numberOfDecimalPlaces = 0, MidpointRounding? midpointRounding = null)
Parameters
Type Name Description
decimal value

The decimal value to normalize.

short numberOfDecimalPlaces

The number of decimal places.

MidpointRounding? midpointRounding

Defines the rounding mode of the value. If no rounding mode is defined, the value is left as it is.

Returns
Type Description
decimal

The normalized decimal value.

Remarks

If a value has more decimal places than numberOfDecimalPlaces and no midpointRounding is defined, the value is left as it is.

Examples

This example illustrates how to use the Normalize(decimal, short, MidpointRounding?) method to normalize a decimal that has two trailing zeroes, to six trailing zero.

This example illustrates how to use the Normalize(decimal, short, MidpointRounding?) method to normalize a decimal that has two trailing zeroes, to one trailing zero.

This example illustrates how to use the Normalize(decimal, short, MidpointRounding?) method to normalize a decimal that has four decimal places, to three decimal places rounded to even.

This example illustrates how to use the Normalize(decimal, short, MidpointRounding?) method to normalize a decimal that has four decimal places, to three decimal places rounded away from zero.

  • View Source
Back to top Generated by DocFX