Skip to content

Commit

Permalink
add fload print function (oceanbase#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
hnwyllmm authored Oct 13, 2022
1 parent 89d57d8 commit d63a39f
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/observer/sql/expr/tuple_cell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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++) {
Expand Down
32 changes: 32 additions & 0 deletions src/observer/util/util.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* Copyright (c) 2021 Xie Meiyi([email protected]) 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 <string.h>
#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);
}
19 changes: 19 additions & 0 deletions src/observer/util/util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* Copyright (c) 2021 Xie Meiyi([email protected]) 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 <string>

std::string double2string(double v);

0 comments on commit d63a39f

Please sign in to comment.