From d63a39f538877ab805f3e6f620e70e35eb8e00d5 Mon Sep 17 00:00:00 2001 From: wangyunlai Date: Thu, 13 Oct 2022 14:23:41 +0800 Subject: [PATCH] add fload print function (#88) --- src/observer/sql/expr/tuple_cell.cpp | 4 +++- src/observer/util/util.cpp | 32 ++++++++++++++++++++++++++++ src/observer/util/util.h | 19 +++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 src/observer/util/util.cpp create mode 100644 src/observer/util/util.h diff --git a/src/observer/sql/expr/tuple_cell.cpp b/src/observer/sql/expr/tuple_cell.cpp index c878b31..8f527c4 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 0000000..039dc34 --- /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 0000000..c7db560 --- /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); -- GitLab