mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 19:57:07 +02:00
Adjusting to force all instances to use rounded vs result due to Mage's quirks (#7164)
This commit is contained in:
@@ -41,7 +41,7 @@ namespace Microsoft.Plugin.Calculator
|
||||
}
|
||||
|
||||
var decimalResult = Convert.ToDecimal(result, cultureInfo);
|
||||
var roundedResult = Math.Round(decimalResult, RoundingDigits, MidpointRounding.AwayFromZero);
|
||||
var roundedResult = Round(decimalResult);
|
||||
|
||||
return new CalculateResult()
|
||||
{
|
||||
@@ -50,6 +50,11 @@ namespace Microsoft.Plugin.Calculator
|
||||
};
|
||||
}
|
||||
|
||||
public static decimal Round(decimal value)
|
||||
{
|
||||
return Math.Round(value, RoundingDigits, MidpointRounding.AwayFromZero);
|
||||
}
|
||||
|
||||
private static object TransformResult(object result)
|
||||
{
|
||||
if (result.ToString() == "NaN")
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace Microsoft.Plugin.Calculator
|
||||
|
||||
return new List<Result>
|
||||
{
|
||||
ResultHelper.CreateResult(result.Result, result.RoundedResult, IconPath),
|
||||
ResultHelper.CreateResult(result.RoundedResult, IconPath),
|
||||
};
|
||||
} // We want to keep the process alive if any the mages library throws any exceptions.
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
|
||||
@@ -14,10 +14,10 @@ namespace Microsoft.Plugin.Calculator
|
||||
{
|
||||
public static Result CreateResult(CalculateResult result, string iconPath)
|
||||
{
|
||||
return CreateResult(result.Result, result.RoundedResult, iconPath);
|
||||
return CreateResult(result.RoundedResult, iconPath);
|
||||
}
|
||||
|
||||
public static Result CreateResult(decimal result, decimal roundedResult, string iconPath)
|
||||
public static Result CreateResult(decimal roundedResult, string iconPath)
|
||||
{
|
||||
return new Result
|
||||
{
|
||||
@@ -25,18 +25,19 @@ namespace Microsoft.Plugin.Calculator
|
||||
IcoPath = iconPath,
|
||||
Score = 300,
|
||||
SubTitle = Properties.Resources.wox_plugin_calculator_copy_number_to_clipboard,
|
||||
Action = c => Action(result),
|
||||
Action = c => Action(roundedResult),
|
||||
};
|
||||
}
|
||||
|
||||
public static bool Action(decimal result)
|
||||
public static bool Action(decimal roundedResult)
|
||||
{
|
||||
var ret = false;
|
||||
|
||||
var thread = new Thread(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
Clipboard.SetText(result.ToString(CultureInfo.CurrentUICulture.NumberFormat));
|
||||
Clipboard.SetText(roundedResult.ToString(CultureInfo.CurrentUICulture.NumberFormat));
|
||||
ret = true;
|
||||
}
|
||||
catch (ExternalException)
|
||||
@@ -44,9 +45,11 @@ namespace Microsoft.Plugin.Calculator
|
||||
MessageBox.Show(Properties.Resources.wox_plugin_calculator_copy_failed);
|
||||
}
|
||||
});
|
||||
|
||||
thread.SetApartmentState(ApartmentState.STA);
|
||||
thread.Start();
|
||||
thread.Join();
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user