浮点数保留小数点后3位

This commit is contained in:
aixiao 2022-09-20 14:34:49 +08:00
parent c0ff9cb920
commit d348935757

View File

@ -33,12 +33,12 @@ static int error_log(float l_t, int c_t, char *log_file, char *recv_mail, int _i
return -1;
// 写入日志文件FD
fprintf(fd, "%d.%d.%d %d:%d:%d %s %f℃ %s %f℃\n", (1900 + tmp_ptr->tm_year), (1 + tmp_ptr->tm_mon), tmp_ptr->tm_mday, tmp_ptr->tm_hour, tmp_ptr->tm_min, tmp_ptr->tm_sec, "Raspberry CPU temperature", l_t, "Restartable or shutdown temperature", (float)c_t);
fprintf(fd, "%d.%d.%d %d:%d:%d %s %.3f℃ %s %.3f℃\n", (1900 + tmp_ptr->tm_year), (1 + tmp_ptr->tm_mon), tmp_ptr->tm_mday, tmp_ptr->tm_hour, tmp_ptr->tm_min, tmp_ptr->tm_sec, "Raspberry CPU temperature", l_t, "Restartable or shutdown temperature", (float)c_t);
if (_is == 1) {
if (_alert == 1) {
// 关机活重启时
sprintf(temperature, "%d.%d.%d %d:%d:%d %s %f℃ %s %f℃\n", (1900 + tmp_ptr->tm_year), (1 + tmp_ptr->tm_mon), tmp_ptr->tm_mday, tmp_ptr->tm_hour, tmp_ptr->tm_min, tmp_ptr->tm_sec, "Raspberry CPU temperature", l_t, "Restartable or shutdown temperature",
sprintf(temperature, "%d.%d.%d %d:%d:%d %s %.3f℃ %s %.3f℃\n", (1900 + tmp_ptr->tm_year), (1 + tmp_ptr->tm_mon), tmp_ptr->tm_mday, tmp_ptr->tm_hour, tmp_ptr->tm_min, tmp_ptr->tm_sec, "Raspberry CPU temperature", l_t, "Restartable or shutdown temperature",
(float)c_t);
sprintf(buffer, "email -r %s -s \"Raspberrypi Temperature\" -t \"%s\"", recv_mail, temperature);
fp = popen(buffer, "r");
@ -47,7 +47,7 @@ static int error_log(float l_t, int c_t, char *log_file, char *recv_mail, int _i
} else {
// 正常温度时
if (tmp_ptr->tm_min >= 10 && tmp_ptr->tm_min <= 12) {
sprintf(temperature, "%d.%d.%d %d:%d:%d %s:%f℃\n", (1900 + tmp_ptr->tm_year), (1 + tmp_ptr->tm_mon), tmp_ptr->tm_mday, tmp_ptr->tm_hour, tmp_ptr->tm_min, tmp_ptr->tm_sec, "Raspberry CPU temperature", l_t);
sprintf(temperature, "%d.%d.%d %d:%d:%d %s:%.3f℃\n", (1900 + tmp_ptr->tm_year), (1 + tmp_ptr->tm_mon), tmp_ptr->tm_mday, tmp_ptr->tm_hour, tmp_ptr->tm_min, tmp_ptr->tm_sec, "Raspberry CPU temperature", l_t);
sprintf(buffer, "email -r %s -s \"Raspberrypi Temperature\" -t \"%s\"", recv_mail, temperature);
fp = popen(buffer, "r");
pclose(fp);