Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix rollup #478

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions deps/common/lang/cmath.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* Copyright (c) 2021 OceanBase and/or its affiliates. All rights reserved.
miniob is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details. */
#pragma once

#include <cmath>

using std::round;
4 changes: 3 additions & 1 deletion deps/common/lang/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ See the Mulan PSL v2 for more details. */

#include "common/log/log.h"
#include "common/lang/algorithm.h"
#include "common/lang/cmath.h"
#include "common/lang/iomanip.h"

namespace common {
Expand Down Expand Up @@ -270,7 +271,8 @@ char *substr(const char *s, int n1, int n2)
string double_to_str(double v)
{
char buf[256];
snprintf(buf, sizeof(buf), "%.2f", v);
double rounded_v = round(v * 100.0) / 100.0;
snprintf(buf, sizeof(buf), "%.2f", rounded_v);
size_t len = strlen(buf);
while (buf[len - 1] == '0') {
len--;
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/game/miniob-output-convention.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ NOTE:后台测试程序,是将预先编辑好的Case执行后,将执行结
4. 所有输出不区分大小写
5. 日期(date)输出格式使用:"YYYY-mm-DD"
6. 输出的字符串不使用单引号双引号或其它括起来
7. 浮点数输出,不要带后面多余的0,可以参考C sprintf的%g格式输出,保留两位小数。参考函数 double_to_str
7. 浮点数输出,不要带后面多余的0,四舍五入保留两位小数。参考函数 double_to_str

FAQ
- 某张表或者某个查询结果一行数据都没有,但是依然需要输出表头信息
Expand Down
Loading