public DataRepositoryDataPresenter(IDataRepositoryDataView view, IDataRepositoryTask dataRepositoryTask, IEditObservedDataTask editObservedDataTask) : base(view) { _dataRepositoryTask = dataRepositoryTask; _editObservedDataTask = editObservedDataTask; _numericFormatter = new NumericFormatter <double>(NumericFormatterOptions.Instance); }
public void TestFormat() { var formatter = NumericFormatter.GetInstance(); var numeric = new PropertyDescrption("any", "any", "株"); string formatted; // 整数 formatted = formatter.Format("1", numeric); Assert.AreEqual("1", formatted); formatted = formatter.Format("10000", numeric); Assert.AreEqual("10,000", formatted); formatted = formatter.Format("-1000000", numeric); Assert.AreEqual("-1,000,000", formatted); formatted = formatter.Format("0", numeric); Assert.AreEqual("0", formatted); formatted = formatter.Format("", numeric); Assert.AreEqual("", formatted); // 小数 // 四捨五入で小数点以下1桁に丸める formatted = formatter.Format("1.23456789", numeric); Assert.AreEqual("1.2", formatted); formatted = formatter.Format("12345.6789", numeric); Assert.AreEqual("12,345.7", formatted); formatted = formatter.Format("-999999.9", numeric); Assert.AreEqual("-999,999.9", formatted); formatted = formatter.Format("123.00000000", numeric); Assert.AreEqual("123", formatted); formatted = formatter.Format("0.0", numeric); Assert.AreEqual("0", formatted); }
/// <summary> /// 使用すべきフォーマッタを返します。 /// </summary> /// <param name="description">項目定義</param> /// <returns>フォーマッタ</returns> public static IFormatter Create(PropertyDescrption description = null) { if (description == null) { return(InactionFormatter.GetInstance()); } switch (description.Unit) { case "円": case "百万円": return(CurrencyFormatter.GetInstance()); case "%": return(RatioFormatter.GetInstance()); case "株": case "倍": case "日": case "ヶ月": case "人": return(NumericFormatter.GetInstance()); case "年": default: return(InactionFormatter.GetInstance()); } }
public void should_return_a_message_when_invalid_using_the_display_database_values(double?dbMax, double?valueInHours) { InitRange(null, null, null, dbMax); var formatter = new NumericFormatter <double>(NumericFormatterOptions.Instance); var validation = sut.Validate(x => x.MaxValueInDisplayUnit, valueInHours); validation.IsEmpty.ShouldBeEqualTo(false); validation.Message.ShouldBeEqualTo(PKSimConstants.Rules.Parameter.MaxLessThanDbMaxValue(sut.ParameterName, formatter.Format(sut.DbMaxValueInDisplayUnit.Value), sut.Unit.Name)); }
public OriginDataReportBuilder( IReportGenerator reportGenerator, IDimensionRepository dimensionRepository, IRepresentationInfoRepository representationInfoRepository) { _reportGenerator = reportGenerator; _dimensionRepository = dimensionRepository; _representationInfoRepository = representationInfoRepository; _formatter = new NumericFormatter <double>(NumericFormatterOptions.Instance); }
public void Nullable_Integer_No_Value() { int?testVal = null; var formatter = new NumericFormatter(); var result = formatter.Format(testVal, 0); Assert.Single(result); Assert.True(result.ContainsKey(string.Empty), "Should have a single, empty key"); Assert.Equal(result[string.Empty], string.Empty); }
public static void AddDefaultFormattingFor <TPropertyType>(this FormatInfo formatInfo) { if (!typeof(TPropertyType).IsNumeric()) { return; } var numericFormatter = new NumericFormatter <TPropertyType>(NumericFormatterOptions.Instance); formatInfo.FormatType = FormatType.Custom; formatInfo.Format = new DxFormatterProvider <TPropertyType>(numericFormatter); }
public LabelGenerationOptions() { _intervalRegexCache = new Cache <string, Regex> { { _startPattern, new Regex(createIntervalRegexPattern(_startPattern)) }, { _endPattern, new Regex(createIntervalRegexPattern(_endPattern)) } }; _numericFormatterOptions = new NumericFormatterOptions(); _defaultFormatterOptions = NumericFormatterOptions.Instance; _numericFormatter = new NumericFormatter <double>(_numericFormatterOptions); }
public JournalPageTask( IDatabaseMediator databaseMediator, IEventPublisher eventPublisher, IDialogCreator dialogCreator, IRelatedItemFactory relatedItemFactory) { _databaseMediator = databaseMediator; _eventPublisher = eventPublisher; _dialogCreator = dialogCreator; _relatedItemFactory = relatedItemFactory; _fileSizeFormatter = new NumericFormatter <double>(NumericFormatterOptions.Instance); }
void ReadNumericFormatters(Table numericFormattersTable) { for (int i = 0, readOffset = (int)numericFormattersTable.offset; i < numericFormattersTable.rowCount; i++, readOffset += numericFormattersTable.rowSize) { uint ID = (uint)numericFormattersTable.ReadField(dbReader.rawDB, readOffset, 0); float metricConvSlope = numericFormattersTable.ReadFloatField(dbReader.rawDB, readOffset, 2); uint metricUnitNameId = (uint)numericFormattersTable.ReadField(dbReader.rawDB, readOffset, 3); float metricConvOffset = numericFormattersTable.ReadFloatField(dbReader.rawDB, readOffset, 4); uint englishUnitNameId = (uint)numericFormattersTable.ReadField(dbReader.rawDB, readOffset, 6); NumericFormatters[ID] = new NumericFormatter(this, ID, englishUnitNameId, metricUnitNameId, metricConvSlope, metricConvOffset); } }
public void NumberFormatter() { var handler = new NumericFormatter(); var st = Stopwatch.StartNew(); for (int i = 0; i < 100000; i++) { handler.Handles(typeof(int)); } st.Stop(); Console.WriteLine($"Numeric handles check {st.ElapsedMilliseconds}ms"); Assert.InRange(st.ElapsedMilliseconds, 0, 30); }
protected BaseDataRepositoryDataPresenter(TView view) : base(view) { _numericFormatter = new NumericFormatter <double>(NumericFormatterOptions.Instance); }
/// <summary> /// 解析数字型内容 /// </summary> /// <param name="p_srcValue">掩码类型</param> /// <param name="p_mask">掩码格式</param> /// <returns>解析后的表达式</returns> public static string ParseNumericMask(object p_srcValue, string p_mask) { p_mask = NumericFormatter.Expand(p_mask, CultureInfo.CurrentCulture); int index = p_mask.Replace(@"\\", "//").Replace(@"\;", "/:").IndexOf(';'); NumericFormatter formatter; if (index < 0) { formatter = new NumericFormatter(p_mask, CultureInfo.CurrentCulture); } else { formatter = new NumericFormatter(p_mask.Substring(0, index), CultureInfo.CurrentCulture); } NumericMaskLogic logic = new NumericMaskLogic(formatter.MaxDigitsBeforeDecimalSeparator, formatter.MinDigitsBeforeDecimalSeparator, formatter.MinDigitsAfterDecimalSeparator, formatter.MaxDigitsAfterDecimalSeparator, CultureInfo.CurrentCulture); int maxDigitsAfterDecimalSeparator = formatter.MaxDigitsAfterDecimalSeparator; if (formatter._Is100Multiplied) { maxDigitsAfterDecimalSeparator += 2; } string format = "{0:f" + maxDigitsAfterDecimalSeparator.ToString(CultureInfo.InvariantCulture) + "}"; string input = string.Format(CultureInfo.InvariantCulture, format, new object[] { p_srcValue }); if (formatter._Is100Multiplied) { input = NumericMaskLogic.Mul100(input); } MaskLogicResult result; string testedString = input.Trim(); bool isNegative = false; if (testedString.StartsWith("-")) { testedString = testedString.Substring(1); isNegative = true; } if (IsDecimal(testedString)) { result = logic.GetEditResult(testedString, string.Empty, string.Empty, string.Empty); if (result != null) { result = logic.GetEditResult(string.Empty, string.Empty, result.EditText, string.Empty); } } else { result = logic.GetEditResult(string.Empty, string.Empty, string.Empty, input); } if (result == null) { result = logic.GetEditResult(string.Empty, string.Empty, string.Empty, string.Empty); } if (!isNegative) { return(formatter.Format(result.EditText)); } return("-" + formatter.Format(result.EditText)); }
public RandomPopulationSettingsTeXBuilder(ITeXBuilderRepository builderRepository, IRepresentationInfoRepository infoRepository) { _builderRepository = builderRepository; _infoRepository = infoRepository; _formatter = new NumericFormatter <double>(NumericFormatterOptions.Instance); }
protected override void Context() { _numericOptions = NumericFormatterOptions.Instance; sut = new NumericFormatter <T>(_numericOptions); }
public GenderRatioReportBuilder(IRepresentationInfoRepository representationInfoRepository) { _representationInfoRepository = representationInfoRepository; _formatter = new NumericFormatter <double>(NumericFormatterOptions.Instance); }