public string FormatValue(string value, HistoryValueFormatterOptions options) { if (options is null) { throw new ArgumentNullException(nameof(options)); } if (!decimal.TryParse(value, out var parsedValue)) { // The value is no number so that formatting is not possible at all. return(value); } if (options.Decimals.HasValue) { parsedValue = Math.Round(parsedValue, options.Decimals.Value); } if (!string.IsNullOrEmpty(options.Format)) { return(parsedValue.ToString(options.Format, CultureInfo.InvariantCulture)); } else { return(parsedValue.ToString(CultureInfo.InvariantCulture)); } }
public HistoryValueFormatterOptions Create(IDictionary <string, object> componentSettings, IDictionary <string, object> defaultSettings) { var options = new HistoryValueFormatterOptions(); if (TryGetSetting(HistorySettingName.Decimals, componentSettings, defaultSettings, out var roundDigitsValue)) { options.Decimals = Convert.ToInt32(roundDigitsValue, CultureInfo.InvariantCulture); } if (TryGetSetting(HistorySettingName.Format, componentSettings, defaultSettings, out var formatValue)) { options.Format = Convert.ToString(formatValue); } return(options); }