Improve rounding slightly

This commit is contained in:
niksedk 2022-01-29 13:17:27 +01:00
parent 5429996c0c
commit b331f7e20f

View File

@ -457,7 +457,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
public static int MillisecondsToFramesMaxFrameRate(double milliseconds)
{
int frames = (int)Math.Round(milliseconds / (TimeCode.BaseUnit / GetFrameForCalculation(Configuration.Settings.General.CurrentFrameRate)), MidpointRounding.AwayFromZero);
var frames = (int)Math.Round(milliseconds / (TimeCode.BaseUnit / GetFrameForCalculation(Configuration.Settings.General.CurrentFrameRate)), MidpointRounding.AwayFromZero);
if (frames >= Configuration.Settings.General.CurrentFrameRate)
{
frames = (int)(Configuration.Settings.General.CurrentFrameRate - 0.01);
@ -468,12 +468,12 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
public static int FramesToMilliseconds(double frames)
{
return (int)Math.Round(frames * (TimeCode.BaseUnit / GetFrameForCalculation(Configuration.Settings.General.CurrentFrameRate)));
return (int)Math.Round(frames * (TimeCode.BaseUnit / GetFrameForCalculation(Configuration.Settings.General.CurrentFrameRate)), MidpointRounding.AwayFromZero);
}
public static int FramesToMillisecondsMax999(double frames)
{
int ms = (int)Math.Round(frames * (TimeCode.BaseUnit / GetFrameForCalculation(Configuration.Settings.General.CurrentFrameRate)));
var ms = (int)Math.Round(frames * (TimeCode.BaseUnit / GetFrameForCalculation(Configuration.Settings.General.CurrentFrameRate)), MidpointRounding.AwayFromZero);
return Math.Min(ms, 999);
}
@ -669,7 +669,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
public static SubtitleFormat FromName(string formatName, SubtitleFormat defaultFormat)
{
string trimmedFormatName = formatName.Trim();
var trimmedFormatName = formatName.Trim();
foreach (var format in AllSubtitleFormats)
{
if (format.Name.Trim().Equals(trimmedFormatName, StringComparison.OrdinalIgnoreCase) ||
@ -682,7 +682,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
return defaultFormat;
}
private static IList<SubtitleFormat> GetOrderedFormatsList(IList<SubtitleFormat> unorderedFormatsList)
private static IList<SubtitleFormat> GetOrderedFormatsList(IEnumerable<SubtitleFormat> unorderedFormatsList)
{
IEnumerable<SubtitleFormat> newSelectedFormats = new[] { Utilities.GetSubtitleFormatByFriendlyName(Configuration.Settings.General.DefaultSubtitleFormat) };
if (!string.IsNullOrEmpty(Configuration.Settings.General.FavoriteSubtitleFormats))