Money

Field: static readonly Money MinValue

The lowest value is Money. Currency is the default CurrencyCode value (XXX). The quantity is the lowest decimal value.

    Money.MinValue; //-79,228,162,514,264,337,593,543,950,335XXX

The value can be converted to string and parse again without getting an overflow error.

    string minMoneyValue = Money.MinValue.ToString();
    Money money = Money.Parse(minMoneyValue);

Field: static readonly Money MaxValue

It is the greatest value for Money. Currency is the default CurrencyCode value (XXX). The quantity is the largest decimal value.

    Money.MaxValue; //79,228,162,514,264,337,593,543,950,335XXX

The value can be converted to string and parse again without getting an overflow error.

    string maxMoneyValue = Money.MaxValue.ToString();
    Money money =Money.Parse(maxMoneyValue);

Method: static Money Parse(String)

creates the Money object with the quantity and currency values ​​of the string type. Parse type is TreatLastTwoDigitsAsDecimalDigitsWhenThereIsNoDecimalPoint (2). If the amount to be parse has a decimal part, the first 2 digits of the decimal part of the quantity are taken and parse. If the amount to be parse does not have a decimal part, they are regarded as the first 2 digits of the decimal part and the parse is done.

    Money.Parse("100.00CLP", MoneyParseType.TreatLastTwoDigitsAsDecimalDigitsWhenThereIsNoDecimalPoint); //100.00 CLP
    Money.Parse("100CLP", MoneyParseType.TreatLastTwoDigitsAsDecimalDigitsWhenThereIsNoDecimalPoint); //1.00 CLP

If the moneyString value does not contain currency, the Money object is created with the default currency (XXX).

    Money.Parse("100", MoneyParseType.TreatLastTwoDigitsAsDecimalDigitsWhenThereIsNoDecimalPoint); //1.00 XXX
Parameter Name Description
moneyString amount and currency to parse

Error Type: ArgumentNullException (This error is thrown if the value set to null.)

Error Type: FormatException (This error is thrown if it comes in a format outside the (-)###.#####___, (-)###.#####, (-)######___ and (-)####### format.)


Method: static Money Parse(String, MoneyParseType)

Creates the Money object with the quantity and currency value of the string type If the parseType value is ExpectDecimalPointOnlyWhenThereAreDecimalDigits(1), no intervention is made for the amount to be parse. If the amount to be parse has a decimal fraction, the amount in the Money object that occurs after the parse is the same as decimal. If the amount to be parse does not have a decimal part, the amount of money that occurs is in decimal type and the decimal part is empty

    Money.Parse("100.00CLP", MoneyParseType.ExpectDecimalPointOnlyWhenThereAreDecimalDigits); //100.00 CLP
    Money.Parse("100CLP", MoneyParseType.ExpectDecimalPointOnlyWhenThereAreDecimalDigits); //100 CLP

If the parseType value is TreatLastTwoDigitsAsDecimalDigitsWhenThereIsNoDecimalPoint (2), the last 2 digits of the quantity to be parse are assumed to be decimal numbers. If the amount to be parse has a decimal part, the first 2 digits of the decimal part of the quantity are taken and parse. If the amount to be parse does not have a decimal part, one of them is parsed by accepting the step as the first 2 digits of the decimal part.

    Money.Parse("100.00CLP", MoneyParseType.TreatLastTwoDigitsAsDecimalDigitsWhenThereIsNoDecimalPoint); //100.00 CLP
    Money.Parse("100CLP", MoneyParseType.TreatLastTwoDigitsAsDecimalDigitsWhenThereIsNoDecimalPoint); //1.00 CLP

If the moneyString value does not contain currency, the Money object default currency (XXX) is created.

    Money.Parse("100", MoneyParseType.TreatLastTwoDigitsAsDecimalDigitsWhenThereIsNoDecimalPoint); //1.00 XXX
Parameter Name Description
moneyString amount and currency to parse
parseType The method to be used in the parse process. ExpectDecimalPointOnlyWhenThereAreDecimalDigits(1), TreatLastTwoDigitsAsDecimalDigitsWhenThereIsNoDecimalPoint(2)

Error Type: ArgumentNullException (This error is thrown if the value set to null.)

Error Type: FormatException (This error is thrown if it comes in a format outside the (-)###.#####___, (-)###.#####, (-)######___ and (-)####### format.)


Constructor(Decimal, CurrencyCode)

The Money object is created with the given quantity and currency values.

Money objects can be created with amounts of money of type double, decimal, and int.

    new Money(12.5m, CurrencyCode.TRY); // 12.5 TRY;
    new Money(12.5m, CurrencyCode.TRY); //12.5m TRY;
    new Money(12m, CurrencyCode.TRY); //12 TRY;

The decimal part of the amount of money can be up to 6 digits. If the decimal part exceeds 6 digits, it is rounded up to 6 digits.

    new Money(15.45678797m,CurrencyCode.TRY); //15.456788 TRY
Parameter Name Description
value quantity in decimal type
currency The CurrencyCode type currency

Method: Money Convert(CurrencyCode, Int32)

It allows you to translate the data into a different currency.

    2.USD().Convert(CurrencyCode.TRY, 2); //4 TRY
Parameter Name Description
targetCurrency currency to be converted
exchangeRate Foreign currency exchange rate difference between old and new currency

Method: Money Convert(CurrencyCode, Double)

It allows you to translate the data into a different currency.

    2.USD().Convert(CurrencyCode.TRY, 1.5); //3 TRY
Parameter Name Description
targetCurrency currency to be converted
exchangeRate Exchange rate in double type difference between old and new currency

Method: Money Convert(CurrencyCode, Decimal)

It allows you to translate the data into a different currency.

    2.USD().Convert(CurrencyCode.TRY, 1.5); //3 TRY
Parameter Name Description
targetCurrency currency to be converted
exchangeRate Exchange rate in decimal type difference between old and new currency

Property: decimal Value

Returns the amount of the data.

    new Money(15.45m,CurrencyCode.TRY).Value; //15.45

Property: CurrencyCode Currency

Returns the amount of the data.

    new Money(15.45m,CurrencyCode.TRY).Currency; //TRY

Method: Money Round(Int32)

The amount is rounded by rolling the precision fine.

    0.000049.TRY().Round(5); //0.00005 TRY

Rounding to maximum 6 digits is done. If rounding is done with a number greater than 6, rounding is done with 6 digits

    0.000049.TRY().Round(7); //0.000049 TRY

No rounding can be done with negative precision.

    0.0049.TRY().Round(-1); //ArgumentOutOfRangeException
Parameter Name Description
precision number of decimal digits to round

Method: string ToString()

The data is returned by removing the divisor of the string type and the decimal part.

    10.2.TRY().ToString()); //1020TRY
    0.2.TRY().ToString()); //20TRY
    0.02.TRY().ToString()); //2TRY
    0.TRY().ToString()); //0TRY

Method: string ToString(Boolean)

Returns the data type by string and formatted according to the selected CultureInfo.

    Thread.CurrentThread.CurrentCulture = new CultureInfo("tr-TR");
    10.20.TRY().ToString(true); //10,20 ₺

    Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
    10.20.TRY().ToString(true); //₺ 10,20
Parameter Name Description
format bool type format option

Method: string ToString(MoneyFormatOptions)

Returns the value as a string. If the options value is None(0), it returns by removing the divisor in the decimal part.

    10.2.TRY().ToString()); //1020TRY
    0.2.TRY().ToString()); //20TRY
    0.02.TRY().ToString()); //2TRY
    0.TRY().ToString()); //0TRY

If the option value is Format(2) returns the data formatted and string type according to the selected CultureInfo.

    Thread.CurrentThread.CurrentCulture = new CultureInfo("tr-TR");
    10.20.TRY().ToString(MoneyFormatOptions.Format); //10,20 ₺

    Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
    10.20.TRY().ToString(MoneyFormatOptions.Format); //₺ 10,20

If the options value is ForceDecimalPoint(1), point separators are forced for currencies that use two digits and gold.

    0.666.TRY().ToString(MoneyFormatOptions.ForceDecimalPoint); //0.67 TRY
    0.66.TRY().ToString(MoneyFormatOptions.ForceDecimalPoint); //0.66 TRY 
    6.6.TRY().ToString(MoneyFormatOptions.ForceDecimalPoint); //6.60 TRY
Parameter Name Description
options Format information in MoneyFormatOptions(enum) type. None(0), ForceDecimalPoint(1),Format(2)

Method: object Clone()

Money returns the object type by creating a new object with the data.


Method: int CompareTo(Object)

If the value of the given object is greater than the value of the Money data, it returns -1, 0 if it is equal, and 1 if it is smaller. The given object must be of type Money.

Parameter Name Description
obj Object to be compared

Error Type: ArgumentException (This error is thrown if the value is not Money type.)


Method: int CompareTo(Money)

If the value of the given object is greater than the value of the Money data, it returns -1, 0 if it is equal, and 1 if it is smaller.

Parameter Name Description
other Money object to compare

Extension Method: static Money ToMoney(Decimal, CurrencyCode)

It creates and returns a Money object with a value of type decimal.

    15m.ToMoney(CurrencyCode.TRY).ToString(); //1500 TRY
Parameter Name Description
source Amount of money
currency Currency of money

Extension Method: static Money ToMoney(Double, CurrencyCode)

Creates and returns a Money object with a value of type double.

    15.5.ToMoney(CurrencyCode.TRY).ToString(); //1550 TRY
Parameter Name Description
source Amount of money
currency Currency of money

Extension Method: static Money ToMoney(Int32, CurrencyCode)

Creates and returns a Money object with a value of type int.

    15.ToMoney(CurrencyCode.TRY).ToString(); //1500 TRY
Parameter Name Description
source Amount of money
currency Currency of money

Extension Method: static Money Min(Money})

Returns the object with the smallest value of the Money list.

    List<Money> moneyList = new List<Money> { 7.TRY(), 5.TRY(), 9.TRY() };
    moneyList.Min(); //5.TRY()

    List<Money> testingList = new List<Money> { 1.TRY(), 2.USD() };
    testingList.Min(); //InvalidOperationException

    new List<Money>().Min(); //InvalidOperationException
Parameter Name Description
source Money list

Error Type: InvalidOperationException (This error is thrown if there are objects with different currencies in the list.)


Extension Method: static Money MinOrDefault(Money}, Money)

If the Money list is not empty, it returns the object with the lowest value of the list. If no listener is present, the default value is returned.

    List<Money> moneyList = new List<Money> { 7.TRY(), 5.TRY(), 9.TRY() };
    moneyList.MinOrDefault(0.TRY()); //5.TRY()

    new List<Money>().MinOrDefault(0.TRY()); //0.TRY()
Parameter Name Description
source Money list

Error Type: InvalidOperationException (This error is thrown if there are objects with different currencies in the list.)


Extension Method: static Money Max(Money})

Returns the object with the biggest value of the Money list.

    List<Money> moneyList = new List<Money> { 7.TRY(), 5.TRY(), 9.TRY() };
    moneyList.Max(); //9.TRY()

    List<Money> testingList = new List<Money> { 1.TRY(), 2.USD() };
    testingList.Max(); //InvalidOperationException

    new List<Money>().Max(); //InvalidOperationException
Parameter Name Description
source Money list

Error Type: InvalidOperationException (This error is thrown if there are objects with different currencies in the list.)


Extension Method: static Money MaxOrDefault(Money}, Money)

If the Money list is not empty, it returns the object with the highest value of the list. If no listener is present, the default value is returned.

    List<Money> moneyList = new List<Money> { 7.TRY(), 5.TRY(), 9.TRY() };
    moneyList.MinOrDefault(0.TRY()); //5.TRY()

    new List<Money>().MinOrDefault(0.TRY()); //0.TRY()
Parameter Name Description
source Money list

Error Type: InvalidOperationException (This error is thrown if there are objects with different currencies in the list.)


Extension Method: static Money Average(Money})

Returns the average value of the Money list.

    List<Money> moneyList = new List<Money> { 7.TRY(), 5.TRY(), 9.TRY() };
    moneyList.Average(); //7.TRY()

    List<Money> testingList = new List<Money> { 1.TRY(), 2.USD() };
    testingList.Average(); //InvalidOperationException

    new List<Money>().Average(); //InvalidOperationException
Parameter Name Description
source Money list

Error Type: InvalidOperationException (This error is thrown if there are objects with different currencies in the list.)


Extension Method: static Money AverageOrDefault(Money}, Money)

Returns the average value of the list if the money list element is present. If list is empty, the default value is returned.

    List<Money> moneyList = new List<Money> { 7.TRY(), 5.TRY(), 9.TRY() };
    moneyList.AverageOrDefault(0.TRY()); //7.TRY()

    new List<Money>().AverageOrDefault(0.TRY()); //0.TRY()
Parameter Name Description
source Money list

Error Type: InvalidOperationException (This error is thrown if there are objects with different currencies in the list.)


Extension Method: static Money Sum(Money})

Returns the total value of the Money list.

    List<Money> moneyList = new List<Money> { 7.TRY(), 5.TRY(), 9.TRY() };
    moneyList.Sum(); //21.TRY()

    List<Money> testingList = new List<Money> { 1.TRY(), 2.USD() };
    testingList.Sum(); //InvalidOperationException

    new List<Money>().Sum(); //InvalidOperationException
Parameter Name Description
source Money list

Error Type: InvalidOperationException (This error is thrown if there are objects with different currencies in the list.)


Extension Method: static Money SumOrDefault(Money}, Money)

Returns the total value of the listen if the money list has elements. If the list is empty, the default value is returned.

    List<Money> moneyList = new List<Money> { 7.TRY(), 5.TRY(), 9.TRY() };
    moneyList.SumOrDefault(0.TRY()); //21.TRY()

    new List<Money>().SumOrDefault(0.TRY()); //0.TRY()
Parameter Name Description
source Money list

Error Type: InvalidOperationException (This error is thrown if there are objects with different currencies in the list.)