IOverhead.GetCurrencyRates Method

Gets all the currencies listed in the Currencies sheet with their rates.
Function GetCurrencyRates() As Dictionary(Of String, Double)
This language is not supported or no code example is available.
Dictionary<string, double> GetCurrencyRates()
This language is not supported or no code example is available.

Return Value

Dictionary<string, double>

A dictionary containing currency names and their rates. The key is the currency name in uppercase (e.g. "USD"), the value is the rate.

Remarks
 

The same rates may be expressed in multiple forms. The form where the current currency of the estimate has the value 1, is called normalized. This is what is displayed to the user in the Currency sheet. For example, all the following rates are the same:

 a)
 [EUR, 100]
 [USD, 200]
 [GBP, 400]
 b)
 [EUR, 1]
 [USD, 2]
 [GBP, 4]
 c)
 [EUR, 0.5]
 [USD, 1]
 [GBP, 2]
 					
If the estimate currency is USD, then the option c) is normalized, because the rate of USD is 1.

The rates returned by the GetCurrencyRates are not guaranteed to be normalized. (Starting with QDV 7.23.1096 they are returned as normalized, but not in the older versions.) So to get the normalized values, you need to divide the returned values by the rate of the currency of the estimate:

 public static void EntryMethod(Qdv.UserApi.IEstimate es, Qdv.UserApi.ICallingContext context)
 {
 	var rates = es.CurrentVersion.Overhead.GetCurrencyRates();
 	rates = NormalizeCurrencyRates(es, rates);
 }
 
 /// <summary>
 /// Normalizes the rates according to the currency of the estimate.
 /// This means that the current currency of the estimate will have the value 1.
 /// </summary>
 /// <param name="es">The estimate.</param>
 /// <param name="rates">The rates to normalize.</param>
 /// <returns>Normalized rates.</returns>
 private static Dictionary<string, double> NormalizeCurrencyRates(IEstimate es, Dictionary<string, double> rates)
 {
 	var normalizedRates = new Dictionary<string, double>();
 	string masterCurrency = es.CurrentVersion.Overhead.GetCurrencyOfEstimate();
 	double masterCurrencyRate = 1;
 	rates.TryGetValue(masterCurrency, out masterCurrencyRate);
 	foreach (string currency in rates.Keys)
 	{
 		var rate = rates[currency];
 		rate /= masterCurrencyRate;
 		normalizedRates.Add(currency, rate);
 	}
 
 	return normalizedRates;
 }
 
 					

On the other hand, SetCurrencyRates method always expect the normalized rates. Otherwise, unexpected rates will be set! So always ensure that you pass normalized rates. You can use the NormalizeCurrencyRates method from the above example before each call to SetCurrencyRates.

Version
 
Available since QDV 7.13.0001.

.NET Framework

Supported in: 4.8, 4.7, 4.6, 4.5.2

In this article

Definition