0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 03:52:22 +02:00

command: simplify printing floats as integers

For this purpose, the printf precision specifier can be used.
No need to call lrint.
This commit is contained in:
nanahi 2024-06-03 08:01:00 -04:00 committed by Kacper Michajłow
parent 9fa8101847
commit b77c5168b4

View File

@ -388,7 +388,7 @@ static char *cut_osd_list(struct MPContext *mpctx, char *text, int pos)
static char *format_delay(double time)
{
return talloc_asprintf(NULL, "%d ms", (int)lrint(time * 1000));
return talloc_asprintf(NULL, "%.f ms", time * 1000);
}
// Property-option bridge. (Maps the property to the option with the same name.)
@ -791,10 +791,10 @@ static int mp_property_percent_pos(void *ctx, struct m_property *prop,
};
return M_PROPERTY_OK;
case M_PROPERTY_PRINT: {
int pos = get_percent_pos(mpctx);
double pos = get_current_pos_ratio(mpctx, false);
if (pos < 0)
return M_PROPERTY_UNAVAILABLE;
*(char **)arg = talloc_asprintf(NULL, "%d", pos);
*(char **)arg = talloc_asprintf(NULL, "%.f", pos * 100);
return M_PROPERTY_OK;
}
}
@ -1670,7 +1670,7 @@ static int mp_property_volume(void *ctx, struct m_property *prop,
};
return M_PROPERTY_OK;
case M_PROPERTY_PRINT:
*(char **)arg = talloc_asprintf(NULL, "%i", (int)opts->softvol_volume);
*(char **)arg = talloc_asprintf(NULL, "%.f", opts->softvol_volume);
return M_PROPERTY_OK;
}
@ -3372,7 +3372,7 @@ static int mp_property_packet_bitrate(void *ctx, struct m_property *prop,
if (action == M_PROPERTY_PRINT) {
rate /= 1000;
if (rate < 1000) {
*(char **)arg = talloc_asprintf(NULL, "%d kbps", (int)rate);
*(char **)arg = talloc_asprintf(NULL, "%.f kbps", rate);
} else {
*(char **)arg = talloc_asprintf(NULL, "%.3f Mbps", rate / 1000.0);
}