diff --git a/src/observer/sql/expr/tuple_cell.cpp b/src/observer/sql/expr/tuple_cell.cpp index c878b31c632307da84b4bf3c28a0ff843d9f65fc..8f527c41cfaf1ecb729eacf46b03dca03e17f3ec 100644 --- a/src/observer/sql/expr/tuple_cell.cpp +++ b/src/observer/sql/expr/tuple_cell.cpp @@ -16,6 +16,7 @@ See the Mulan PSL v2 for more details. */ #include "storage/common/field.h" #include "common/log/log.h" #include "util/comparator.h" +#include "util/util.h" void TupleCell::to_string(std::ostream &os) const { @@ -24,7 +25,8 @@ void TupleCell::to_string(std::ostream &os) const os << *(int *)data_; } break; case FLOATS: { - os << *(float *)data_; + float v = *(float *)data_; + os << double2string(v); } break; case CHARS: { for (int i = 0; i < length_; i++) { diff --git a/src/observer/util/util.cpp b/src/observer/util/util.cpp new file mode 100644 index 0000000000000000000000000000000000000000..039dc34c5001a62ddc143ea5a804f6c642852150 --- /dev/null +++ b/src/observer/util/util.cpp @@ -0,0 +1,32 @@ +/* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and 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. */ + +// +// Created by wangyunlai on 2022/9/28 +// + +#include +#include "util/util.h" + +std::string double2string(double v) +{ + char buf[256]; + snprintf(buf, sizeof(buf), "%.2f", v); + size_t len = strlen(buf); + while (buf[len - 1] == '0') { + len--; + + } + if (buf[len - 1] == '.') { + len--; + } + + return std::string(buf, len); +} diff --git a/src/observer/util/util.h b/src/observer/util/util.h new file mode 100644 index 0000000000000000000000000000000000000000..c7db5605eae62e9e15902fc30f99b33531257bd1 --- /dev/null +++ b/src/observer/util/util.h @@ -0,0 +1,19 @@ +/* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and 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. */ + +// +// Created by wangyunlai on 2022/9/28 +// + +#pragma once + +#include + +std::string double2string(double v);