Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue-33026/feat: unit converter, improve data units #33563

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public class ConvertModel

public string ToUnit { get; set; }

public string Standard { get; set; }

public ConvertModel()
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,26 @@ public static double ConvertInput(ConvertModel convertModel, QuantityInfo quanti

if (fromUnit != null && toUnit != null)
{
return UnitsNet.UnitConverter.Convert(convertModel.Value, fromUnit, toUnit);
}

return double.NaN;
{
// Check the standard and adjust the toUnit accordingly
if (convertModel.Standard == "IEC")
{
// Convert toUnit to IEC equivalent if necessary
toUnit = ConvertToIECUnit(toUnit);
}
else if (convertModel.Standard == "ITU")
{
// Convert toUnit to ITU equivalent if necessary
toUnit = ConvertToITUUnit(toUnit);
}

return UnitsNet.UnitConverter.Convert(convertModel.Value, fromUnit, toUnit);
}

return double.NaN;
}


/// <summary>
/// Given ConvertModel returns collection of possible results.
Expand Down
Loading