[PTRun][UnitConverter]Preserve more significant digits (#35073)

* [PTRun][UnitConverter]Preserve more significant digits

* Use StringComparison.OrdinalIgnoreCase
This commit is contained in:
PesBandi
2024-10-18 15:51:57 +02:00
committed by GitHub
parent dd5cd2a570
commit e99b52fb35
4 changed files with 28 additions and 66 deletions

View File

@@ -11,8 +11,6 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter
{
public static class UnitHandler
{
private static readonly int _roundingSignificantDigits = 4;
private static readonly QuantityInfo[] _included = new QuantityInfo[]
{
Acceleration.Info,
@@ -59,23 +57,6 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter
return null;
}
/// <summary>
/// Rounds the value to the predefined number of significant digits.
/// </summary>
/// <param name="value">Value to be rounded</param>
public static double Round(double value)
{
if (value == 0.0D)
{
return 0;
}
var power = Math.Floor(Math.Log10(Math.Abs(value)));
var exponent = Math.Pow(10, power);
var rounded = Math.Round(value / exponent, _roundingSignificantDigits) * exponent;
return rounded;
}
/// <summary>
/// Given parsed ConvertModel, computes result. (E.g "1 foot in cm").
/// </summary>
@@ -106,7 +87,7 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter
if (!double.IsNaN(convertedValue))
{
UnitConversionResult result = new UnitConversionResult(Round(convertedValue), convertModel.ToUnit, quantityInfo);
UnitConversionResult result = new UnitConversionResult(convertedValue, convertModel.ToUnit, quantityInfo);
results.Add(result);
}
}