Compare commits

..

2 Commits

Author SHA1 Message Date
Leilei Zhang
e17116964b remove unuse 2025-06-20 16:14:22 +08:00
Leilei Zhang
14c9a40bfa apps 2025-06-20 16:07:54 +08:00
3 changed files with 6 additions and 27 deletions

View File

@@ -22,7 +22,6 @@
"CalculatorEngineCommon.dll",
"PowerToys.ManagedTelemetry.dll",
"PowerToys.ManagedCommon.dll",
"PowerToys.ManagedCsWin32.dll",
"PowerToys.Common.UI.dll",
"PowerToys.Settings.UI.Lib.dll",
"PowerToys.GPOWrapper.dll",

View File

@@ -84,7 +84,11 @@ public static class CalculateEngine
var decimalResult = Convert.ToDecimal(result, cultureInfo);
var roundedResult = FormatMax15Digits(decimalResult, cultureInfo);
// Remove trailing zeros from the decimal string representation (e.g., "1.2300" -> "1.23")
// This is necessary because the value extracted from exprtk may contain unnecessary trailing zeros.
var formatted = decimalResult.ToString("G29", cultureInfo);
decimalResult = Convert.ToDecimal(formatted, cultureInfo);
var roundedResult = Round(decimalResult);
return new CalculateResult()
{
@@ -97,28 +101,4 @@ public static class CalculateEngine
{
return Math.Round(value, RoundingDigits, MidpointRounding.AwayFromZero);
}
/// <summary>
/// Format a decimal so that the output contains **at most 15 total digits**
/// (integer + fraction, not counting the decimal point or minus sign).
/// Any extra fractional digits are rounded using “away-from-zero” rounding.
/// Trailing zeros in the fractional part—and a dangling decimal point—are removed.
/// Examples
/// 1.9999999999 → "1.9999999999"
/// 100000.9999999999 → "100001"
/// 1234567890123.45 → "1234567890123.45"
/// </summary>
private static decimal FormatMax15Digits(decimal value, CultureInfo cultureInfo)
{
var absValue = Math.Abs(value);
var integerDigits = absValue >= 1 ? (int)Math.Floor(Math.Log10((double)absValue)) + 1 : 1;
var maxDecimalDigits = Math.Max(0, 15 - integerDigits);
var rounded = Math.Round(value, maxDecimalDigits, MidpointRounding.AwayFromZero);
var formatted = rounded.ToString("G29", cultureInfo);
return Convert.ToDecimal(formatted, cultureInfo);
}
}

View File

@@ -12,4 +12,4 @@ To view the full docs, you can head over to [our docs site](https://go.microsoft
There are samples of just about everything you can do in [the samples project].
Head over there to see basic usage of the APIs.
[the samples project]: https://github.com/microsoft/PowerToys/tree/main/src/modules/cmdpal/ext/SamplePagesExtension
[the samples project]: https://github.com/microsoft/PowerToys/tree/main/src/modules/cmdpal/Exts/SamplePagesExtension