当前位置:网站首页>GBase 8a对 double 数值进行 round 取舍结果不是四舍五入问题分析及解决方案
GBase 8a对 double 数值进行 round 取舍结果不是四舍五入问题分析及解决方案
2022-04-21 19:48:00 【龘辰】
首先说一下round函数:
ROUND(X)返回参数 X 四舍五入到最近的整数后的值。
ROUND(X,D)返回的 X 值,保留到小数点后 D 位(第 D 位的保留方式为四舍五入)。
问题现象
对 double 类型数值进行 round 取舍,结果不是四舍五入。
问题复现
gbase> create table t(c1 double);Query OK, 0 rows affected (Elapsed: 00:00:00.55)gbase> insert into t values(41.325);Query OK, 1 row affected (Elapsed: 00:00:00.03)gbase> select c1,round(c1,2) from t;+--------+-------------+| c1 | round(c1,2) |+--------+-------------+| 41.325 | 41.32 |+--------+-------------+1 row in set (Elapsed: 00:00:00.00)
问题分析
DOUBLE 代表一个浮点型数值,它所存储的数值不是一个准确值。所以造成了结果的差别。
对 double 类型作 round,采取了“四舍六入五凑偶”的规则。
“四舍六入五凑偶”规则说明
- 四舍”是指≤4 时舍去;
- "六入"是指≥6 时进上;
- "五凑偶"指的是根据 5 后面的数字来定,当 5 后有数时,舍 5 入 1;
- 当 5 后无数或为 0 时,分两种情况:
(1) 5 前为奇数,舍 5 入 1;
(2)5 前为偶数,舍 5 不进。
解决方案
限制物化结果(中间结果和最终结果)记录数的参数_gbase_result_threshold 总结如下:
- 参数值为 0 时,对物化结果集不做限制。
- 参数值不为 0 时,取值范围为[1,_gbase_result_threshold]。
- _gbase_result_threshold 的最小值为 0(为 0 时对物化结果集不做限制),最大值为 140737488355325(2^47-3,GBase 8a Express 引擎以前支持的物化结果的最大记录数),默认值为 137438953472(2 的 37 次方)。
gbase> show variables like '%_gbase_result_threshold%';+-------------------------+--------------+|Variable_name | Value |+-------------------------+--------------+| _gbase_result_threshold | 137438953472 |+-------------------------+--------------+1 row in set (Elapsed: 00:00:00.00)
版权声明
本文为[龘辰]所创,转载请带上原文链接,感谢
https://blog.csdn.net/Mr_dar/article/details/124321890
边栏推荐
猜你喜欢

High performance distributed cache redis - redis infrastructure and cache principle - continuous update

居家第二十一天的成果

MySQL之2003-Can‘t connect to MySQL server on ‘localhost‘(10038)的解决办法

mui选项卡怎么实现循环轮播

Today's sleep quality record is 83 points
![Sword finger offer: [day 29 dynamic programming (difficult)] --- > n dice points](/img/fe/1691eda08b8dbda532abc716d09143.png)
Sword finger offer: [day 29 dynamic programming (difficult)] --- > n dice points

Xinguan is merciless, human beings have feelings, Xinlong agriculture ensures people's livelihood and jointly fights the epidemic -- condolences to the front line of fighting the epidemic, love the el

Interface component telerik UI for WPF Getting Started Guide - color theme generator

leetcode344. 反转字符串

有趣的灵魂千篇一律,电脑滑动关机,仅需2步
随机推荐
flink中checkpoint机制随笔
MySQL修改root用户密码
Redis基础
[maximum value of jz47 gift]
MKL library matrix multiplication
Digital business cloud community property platform system solution - easy property management and leveraging potential business opportunities
【转载】devm_xxx机制
Use cmake to build / cmake Command Reference
Dolphin DB vscode plug-in tutorial
getchar,putchar,EOF
MySQL 视图(详解)
High performance distributed cache redis - redis infrastructure and cache principle - continuous update
Redis Lua script detailed explanation of lua script high frequency interview questions
leetcode541. Reverse string II
High end manufacturing enterprise informatization solution, predictive maintenance of industrial e-commerce platform equipment, data and system
OpenCV之OpenCL介绍
int count= cmd. ExecuteNonQuery(); There is a syntax error nearby
Redis installation and configuration startup
高性能分布式缓存Redis--- Redis底层结构和缓存原理 --- 持续更新
80.(leaflet篇)leaflet调用geoserver发布的postgis数据图层