public override void Format(ValueData data) { if (data != null) { data.ValueFormatted = FormatNumber(data.Value); } }
public override void Format(ValueData data) { if (data != null) { data.ValueFormatted = formatMethod(data.Value); } }
private void ThenValuesAreFormattedTo1DecimalPlace() { Assert.IsNotNull(formatter); var data = new ValueData { Value = 96.4444 }; formatter.Format(data); Assert.AreEqual("96.4", data.ValueFormatted); data = new ValueData { Value = 96.5555 }; formatter.Format(data); Assert.AreEqual("96.6", data.ValueFormatted); }
public void TestTruncateDoesNotDoBankersRounding() { var val = 2.5555555; var expectedTruncatedVal = 2.5556; var bankersRounding = MidpointRounding.ToEven; var data = new ValueData { Value = val }; Processor().Truncate(data); Assert.AreEqual(expectedTruncatedVal, data.Value); // Banker's rounding doesn't round to even when >1 digit after decimal point Assert.AreEqual(expectedTruncatedVal, Math.Round(val, DataProcessor<ValueDataProcessor>.DecimalPlaceCount, bankersRounding)); // Different outcomes depending on midpoint rounding method Assert.AreEqual(2, Math.Round(2.5, 0, bankersRounding)); Assert.AreEqual(3, Math.Round(2.5, 0, MidpointRounding.AwayFromZero)); }
public abstract void Format(ValueData data);
public void Build() { var metadataRepo = IndicatorMetadataRepository.Instance; const int indicatorId = IndicatorIds.QuinaryPopulations; Grouping grouping = groupDataReader.GetGroupingsByGroupIdAndIndicatorId(GroupId, indicatorId); area = areasReader.GetAreaFromCode(AreaCode); var metadata = metadataRepo.GetIndicatorMetadata(indicatorId); period = new DataPointOffsetCalculator(grouping, DataPointOffset, metadata.YearType).TimePeriod; // Get data for each sex int overallTotal = 0; foreach (var sexId in sexIds) { IEnumerable<double> vals; if (area.IsCcg) { QuinaryPopulation population = practiceReader.GetCcgQuinaryPopulation(indicatorId, period, AreaCode, sexId); vals = new QuinaryPopulationSorter(population.Values).SortedValues; } else { IList<CoreDataSet> data = groupDataReader.GetCoreDataForAllAges(indicatorId, period, AreaCode, sexId); vals = new QuinaryPopulationSorter(data).SortedValues; } // Add total int total = Convert.ToInt32(Math.Round(vals.Sum(), MidpointRounding.AwayFromZero)); overallTotal += total; Values.Add(sexId, vals); } // Convert to % foreach (var sexId in sexIds) { Values[sexId] = Values[sexId].Select(x => Math.Round((x / overallTotal) * 100, 2, MidpointRounding.AwayFromZero)); } // List size var val = new QofListSizeProvider(groupDataReader, area, GroupId, DataPointOffset, metadata.YearType).Value; if (val.HasValue) { metadata = metadataRepo.GetIndicatorMetadata(QofListSizeProvider.IndicatorId); ListSize = new ValueData { Value = val.Value }; var formatter = NumericFormatterFactory.New(metadata, groupDataReader); formatter.Format(ListSize); } if (area.IsGpPractice && AreOnlyPopulationsRequired == false) { SetEthnicityText(); SetDeprivationDecile(); Shape = practiceReader.GetShape(AreaCode); AdHocValues = new PracticePerformanceIndicatorValues(groupDataReader, AreaCode, DataPointOffset).IndicatorToValue; } }
private string FormatValue(double val, int decimalPlacesDisplayed) { var formatter = NumericFormatterFactory.NewWithLimits(GetMetadata(decimalPlacesDisplayed), null); var data = new ValueData { Value = val }; formatter.Format(data); return data.ValueFormatted; }
private static ValueData Data() { var data = new ValueData { Value = 1.111111111 }; return data; }
private static void AssertValueTruncatedAsExpected(ValueData data) { Assert.AreEqual(1.1111, data.Value); }
private static void AssertValueFormattedAsExpected(ValueData data) { Assert.AreEqual("1.11", data.ValueFormatted); }