public string Encode(IEnumerable <TimedEvent> events) { var places = StepmaniaConstants.DecimalPlaces; return(string.Join(",", events.Select(ev => { var key = _numberFormatter.Format(ev.Offset * 4, places); var value = _numberFormatter.Format(BigRational.IsInfinity(ev.Value) ? (ev.Offset == 0 ? 99999 : -1) : ev.Value, places); return $"{key}={value}"; }))); }
public IHttpActionResult Format(NumberDTO numberDTO) { if (false == ModelState.IsValid) { return(BadRequest(GetModelErrorMessage())); } var number = numberDTO.Number; try { var formattedNumber = _formatter.Format(number); return(Ok(new NumberDTO(formattedNumber))); } catch (FormatException e) { return(BadRequest(e.Message)); } }
/// <summary> /// Executes the padding scenarios. /// </summary> /// <param name="formatter"> /// The formatter parameter can be either a DecimalFormatter, PercentFormatter /// PerMilleFormatter or CurrencyFormatter /// </param> private string DoPaddingScenarios(INumberFormatter formatter) { // Display the properties of the scenario StringBuilder results = new StringBuilder(); results.Append("Padding with "); results.Append(((ISignificantDigitsOption)formatter).SignificantDigits + " significant digits, "); results.Append(((INumberFormatterOptions)formatter).IntegerDigits + " integer digits, "); results.Append(((INumberFormatterOptions)formatter).FractionDigits + " fractional digits\n\n"); // Iterate through the numbers to pad, format them and add them to the results double[] numbersToPad = new double[] { 0.12, 1.2, 10.2, 102 }; foreach (double numberToPad in numbersToPad) { string paddedNumber = formatter.Format(numberToPad); results.Append("Value: " + numberToPad + " Padded: " + paddedNumber + "\n"); } // Add a carriage return at the end of the scenario for readability results.AppendLine(); return(results.ToString()); }
/// <summary> /// Executes the padding scenarios. /// </summary> /// <param name="formatter"> /// The formatter parameter can be either a DecimalFormatter, PercentFormatter /// PerMilleFormatter or CurrencyFormatter /// </param> private string DoPaddingScenarios(INumberFormatter formatter) { // Display the properties of the scenario StringBuilder results = new StringBuilder(); results.Append("Padding with "); results.Append(((ISignificantDigitsOption) formatter).SignificantDigits + " significant digits, "); results.Append(((INumberFormatterOptions) formatter).IntegerDigits + " integer digits, "); results.Append(((INumberFormatterOptions) formatter).FractionDigits + " fractional digits\n\n"); // Iterate through the numbers to pad, format them and add them to the results double[] numbersToPad = new double[] { 0.12, 1.2, 10.2, 102 }; foreach (double numberToPad in numbersToPad) { string paddedNumber = formatter.Format(numberToPad); results.Append("Value: " + numberToPad + " Padded: " + paddedNumber + "\n"); } // Add a carriage return at the end of the scenario for readability results.AppendLine(); return results.ToString(); }