mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-17 06:01:33 -06:00
WebUI: replace rounding function from MooTools
The `round()` returning floating point number is not a good idea. This is due to floating point representation is imprecise and sometimes it cannot faithfully represent a number, for example `0.09 + 0.01 !== 0.1 `. Therefore, it should be avoided and/or utilize other function to achieve the goal. Also, improve `window.qBittorrent.Misc.toFixedPointString()` and add test cases. PR #22281.
This commit is contained in:
@@ -1231,9 +1231,7 @@ window.qBittorrent.DynamicTable ??= (() => {
|
||||
// progress
|
||||
this.columns["progress"].updateTd = function(td, row) {
|
||||
const progress = this.getRowValue(row);
|
||||
let progressFormatted = (progress * 100).round(1);
|
||||
if ((progressFormatted === 100.0) && (progress !== 1.0))
|
||||
progressFormatted = 99.9;
|
||||
const progressFormatted = window.qBittorrent.Misc.toFixedPointString((progress * 100), 1);
|
||||
|
||||
const div = td.firstElementChild;
|
||||
if (div !== null) {
|
||||
@@ -1782,10 +1780,7 @@ window.qBittorrent.DynamicTable ??= (() => {
|
||||
// progress
|
||||
this.columns["progress"].updateTd = function(td, row) {
|
||||
const progress = this.getRowValue(row);
|
||||
let progressFormatted = (progress * 100).round(1);
|
||||
if ((progressFormatted === 100.0) && (progress !== 1.0))
|
||||
progressFormatted = 99.9;
|
||||
progressFormatted += "%";
|
||||
const progressFormatted = `${window.qBittorrent.Misc.toFixedPointString((progress * 100), 1)}%`;
|
||||
td.textContent = progressFormatted;
|
||||
td.title = progressFormatted;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user