mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Fix centisecs rounding in str_time_float
This commit is contained in:
parent
d65ae499a4
commit
7fa331a5e9
|
@ -1,6 +1,7 @@
|
|||
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
||||
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -2885,7 +2886,7 @@ int str_time(int64 centisecs, int format, char *buffer, int buffer_size)
|
|||
|
||||
int str_time_float(float secs, int format, char *buffer, int buffer_size)
|
||||
{
|
||||
return str_time((int64)(secs * 100.0), format, buffer, buffer_size);
|
||||
return str_time(llroundf(secs * 100.0), format, buffer, buffer_size);
|
||||
}
|
||||
|
||||
void str_escape(char **dst, const char *src, const char *end)
|
||||
|
|
|
@ -309,4 +309,7 @@ TEST(Str, StrTimeFloat)
|
|||
char aBuf[64];
|
||||
EXPECT_EQ(str_time_float(123456.78, TIME_DAYS, aBuf, sizeof(aBuf)), 11);
|
||||
EXPECT_STREQ(aBuf, "1d 10:17:36");
|
||||
|
||||
EXPECT_EQ(str_time_float(12.16, TIME_HOURS_CENTISECS, aBuf, sizeof(aBuf)), 8);
|
||||
EXPECT_STREQ(aBuf, "00:12.16");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue