mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-01-22 12:07:07 +01:00
Compare commits
6 Commits
leilzh/app
...
leilzh/dou
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bf3d108367 | ||
|
|
cab8834802 | ||
|
|
d26f0125bb | ||
|
|
718600a379 | ||
|
|
63b13d219c | ||
|
|
1e79a98b2e |
@@ -22,6 +22,7 @@
|
||||
"CalculatorEngineCommon.dll",
|
||||
"PowerToys.ManagedTelemetry.dll",
|
||||
"PowerToys.ManagedCommon.dll",
|
||||
"PowerToys.ManagedCsWin32.dll",
|
||||
"PowerToys.Common.UI.dll",
|
||||
"PowerToys.Settings.UI.Lib.dll",
|
||||
"PowerToys.GPOWrapper.dll",
|
||||
|
||||
@@ -218,13 +218,12 @@ public class UWPApplication : IProgram
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
var capacity = 1024U;
|
||||
PWSTR outBuffer = new PWSTR((char*)(void*)Marshal.AllocHGlobal((int)capacity * sizeof(char)));
|
||||
Span<char> outBuffer = stackalloc char[1024];
|
||||
var source = $"@{{{packageFullName}? {parsed}}}";
|
||||
|
||||
try
|
||||
{
|
||||
PInvoke.SHLoadIndirectString(source, outBuffer.AsSpan()).ThrowOnFailure();
|
||||
PInvoke.SHLoadIndirectString(source, outBuffer).ThrowOnFailure();
|
||||
|
||||
var loaded = outBuffer.ToString();
|
||||
return string.IsNullOrEmpty(loaded) ? string.Empty : loaded;
|
||||
@@ -234,7 +233,7 @@ public class UWPApplication : IProgram
|
||||
try
|
||||
{
|
||||
var sourceFallback = $"@{{{packageFullName}?{parsedFallback}}}";
|
||||
PInvoke.SHLoadIndirectString(sourceFallback, outBuffer.AsSpan()).ThrowOnFailure();
|
||||
PInvoke.SHLoadIndirectString(sourceFallback, outBuffer).ThrowOnFailure();
|
||||
var loaded = outBuffer.ToString();
|
||||
return string.IsNullOrEmpty(loaded) ? string.Empty : loaded;
|
||||
}
|
||||
@@ -243,13 +242,6 @@ public class UWPApplication : IProgram
|
||||
// ProgramLogger.Exception($"Unable to load resource {resourceReference} from {packageFullName}", new InvalidOperationException(), GetType(), packageFullName);
|
||||
return string.Empty;
|
||||
}
|
||||
finally
|
||||
{
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
Marshal.FreeHGlobal((IntPtr)outBuffer.Value);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -84,11 +84,7 @@ public static class CalculateEngine
|
||||
|
||||
var decimalResult = Convert.ToDecimal(result, 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);
|
||||
var roundedResult = FormatMax15Digits(decimalResult, cultureInfo);
|
||||
|
||||
return new CalculateResult()
|
||||
{
|
||||
@@ -101,4 +97,28 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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/Exts/SamplePagesExtension
|
||||
[the samples project]: https://github.com/microsoft/PowerToys/tree/main/src/modules/cmdpal/ext/SamplePagesExtension
|
||||
|
||||
Reference in New Issue
Block a user