blob: a1818a0d78a66217a1586191d123782a3d1795c8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#include "utils/utils.hpp"
#include <cmath>
#include <cstdio>
void format_rate(std::string & s, double rate) {
static const char MAX_FORMAT[] = "00000.00";
if(std::isinf(rate) || std::isnan(rate)) {
rate = 0.0;
}
s.resize(sizeof(MAX_FORMAT));
int wrlen = snprintf(&s[0], s.size(), "%05.2f", rate);
int sz = strlen(s.c_str());
if(sz != wrlen) {
s.assign("ERR");
} else {
s.resize(sz);
}
}
|