public void When_UsingVariousSignificantDigits(double value, uint significantDigits, double expected) { var sut = new SignificantDigitsNumberRounder(); sut.SignificantDigits = significantDigits; var rounded = sut.RoundDouble(value); Assert.AreEqual(expected, rounded); }
private void When_UsingARoundingAlgorithmCore(double value, RoundingAlgorithm roundingAlgorithm, double expected) { var sut = new SignificantDigitsNumberRounder(); sut.SignificantDigits = 2; sut.RoundingAlgorithm = roundingAlgorithm; var rounded = sut.RoundDouble(value); Assert.AreEqual(expected, rounded); }
// Updates TextBox.Text with the formatted Value private void UpdateTextToValue() { if (m_textBox != null) { string newText = ""; var value = Value; if (!double.IsNaN(value)) { // Rounding the value here will prevent displaying digits caused by floating point imprecision. var roundedValue = m_displayRounder.RoundDouble(value); if (ApiInformation.IsTypePresent(NumberFormatter.GetType().FullName)) { newText = NumberFormatter.FormatDouble(roundedValue); } else { newText = roundedValue.ToString($"0." + new string('#', (int)m_displayRounder.SignificantDigits), CultureInfo.CurrentCulture); } } m_textBox.Text = newText; try { m_textUpdating = true; Text = newText; // This places the caret at the end of the text. m_textBox.Select(newText.Length, 0); } finally { m_textUpdating = false; } } }