Copy the codeThe code is as follows:
public void PrintPercentage(int FinishedCount, int TotalCount)
{
decimal finishedPercentage = (FinishedCount) / (TotalCount);
(0, - 1);
((finishedPercentage * 100).ToString("f1") + "%");
}
The purpose of SetCursorPosition is to reset the cursor to, the meaning of the parameters inside is (left, top). The line at the bottom of cmd is ("f1") means retaining a decimal.
Or the purpose can be achieved using "\r", which means that the cursor is returned to the current first line, as follows:
Copy the codeThe code is as follows:
public void PrintPercentage(int FinishedCount, int TotalCount)
{
decimal finishedPercentage = (FinishedCount) / (TotalCount);
("\r" + (finishedPercentage * 100).ToString("f1") + "%");
}
In contrast, the former is more flexible and can be positioned anywhere