protected override void Execute(CodeActivityContext executionContext) { var error = false; try { var value = Convert.ToDouble(Value.Get <string>(executionContext)); FloatValue.Set(executionContext, value); DecimalValue.Set(executionContext, Convert.ToDecimal(Math.Round(value, 2))); MoneyValue.Set(executionContext, new Money { Value = Convert.ToDecimal(Math.Round(value, 2)) }); TruncatedValue.Set(executionContext, Convert.ToInt32(Math.Truncate(value))); RoundedValue.Set(executionContext, Convert.ToInt32(Math.Round(value, 0))); } catch { error = true; } ProcessingError.Set(executionContext, error); }
public static string getFormattedValue(string Format, decimal _value) { string _FormattedValue; int NumberOfDecimals; decimal RoundedValue; if (Format != null && Format != "" && Format.Length > 1) { NumberOfDecimals = Format.Substring(1).ToInt32(); if (NumberOfDecimals > 0) { RoundedValue = Math.Round(_value, NumberOfDecimals); _FormattedValue = RoundedValue.ToString(Format); } else { _FormattedValue = _value.ToString(Format); } } else { _FormattedValue = _value.ToString(); } return(_FormattedValue); }
public double?CalculateReturnsCorrectResult(double?input, int decimals) { var sut = new RoundedValue(new Constant(input), decimals); return(sut.Calculate(null).SingleOrNull()); }