mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-22 03:02:35 +01:00
Improve rounding - thx OmrSi :)
This commit is contained in:
parent
d19b259771
commit
85d0b121fa
@ -4,21 +4,29 @@ using Nikse.SubtitleEdit.Core.SubtitleFormats;
|
||||
|
||||
namespace Test.Logic.SubtitleFormats
|
||||
{
|
||||
[TestClass]
|
||||
public class SubtitleFormatFunctionsTest
|
||||
{
|
||||
[TestMethod]
|
||||
public void MillisecondsToFrames1()
|
||||
{
|
||||
var x = SubtitleFormat.MillisecondsToFrames(500, 25);
|
||||
Assert.AreEqual(x, 13);
|
||||
var frames = SubtitleFormat.MillisecondsToFrames(500, 25);
|
||||
Assert.AreEqual(13, frames);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MillisecondsToFrames2()
|
||||
{
|
||||
var frames = SubtitleFormat.MillisecondsToFrames(499, 25);
|
||||
Assert.AreEqual(12, frames);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void FramesToMilliseconds1()
|
||||
{
|
||||
Configuration.Settings.General.CurrentFrameRate = 25.0;
|
||||
var x = SubtitleFormat.FramesToMilliseconds(1);
|
||||
Assert.AreEqual(x, 40);
|
||||
var ms = SubtitleFormat.FramesToMilliseconds(1);
|
||||
Assert.AreEqual(ms, 40);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -425,7 +425,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
|
||||
public static int MillisecondsToFrames(double milliseconds, double frameRate)
|
||||
{
|
||||
return (int)Math.Round(milliseconds / (TimeCode.BaseUnit / GetFrameForCalculation(frameRate)));
|
||||
return (int)Math.Round(milliseconds / (TimeCode.BaseUnit / GetFrameForCalculation(frameRate)), MidpointRounding.AwayFromZero);
|
||||
}
|
||||
|
||||
public static double GetFrameForCalculation(double frameRate)
|
||||
|
Loading…
Reference in New Issue
Block a user