ROUND function and arithmetic overflow
遇到如下错误
Arithmetic overflow error converting expression to data type numeric.
SELECT ROUND(0.1, 0), ROUND(0.9, 2);
https://stackoverflow.com/questions/33835741/round-function-and-arithmetic-overflow
问题
In MS SQL Server, if I
SELECT ROUND(9.4, 0), ROUND(8.6, 0), ROUND(10.6, 0)
I unsurprisingly get:
9.0 9.0 11.0
But if I do
SELECT ROUND(9.6, 0)
解答
SQL takes the first parameter as the datatype, which is, in this case DECIMAL(2,1). The expected outcome, 10.0, should be of type DECIMAL(3,1) which is why you get the error.
Try:
SELECT ROUND(cast(9.6 as decimal(2,1)), 0)
then try:
SELECT ROUND(cast(9.6 as decimal(3,1)), 0)
分析
ROUND(0.9, 2);
需要进位了,0.9对应decimal(1,1)。但是进位之后,0.9变成1。其实类型变为decimal(1,0)。
decimal对应的类型(长度,小数位数)(length,scale)。
0.9数字长度为1,小数位数也是1。
1数字长度为1,小数位数是0。
SELECT ROUND(CAST(0.9 AS DECIMAL(1, 0)), 0);
ROUND function and arithmetic overflow的更多相关文章
- javascript Round Function
var rounded = Math.round( number * 10 ) / 10; // round to one digit var rounded = Math.round( number ...
- CF刷题-Codeforces Round #481-D. Almost Arithmetic Progression
题目链接:https://codeforces.com/contest/978/problem/D 题解: 题目的大意就是:这组序列能否组成等差数列?一旦构成等差数列,等差数列的公差必定确定,而且,对 ...
- 数值溢出(arithmetic overflow)问题与解决方案
0. 典型场景 两数相加(乘法).两数相减.一个数的阶乘,一个数的幂,这些统统可能造成数值的溢出: 避免数值溢出的方法: 当把一个计算出的很大的数赋值给一个 int(2^31-1)类型变量存储时,一般 ...
- Round() 四舍五入 js银行家算法(转)
首先问一下round(0.825,2) 返回的结果,大家猜一猜, 首先SQL server 返回的是 0.83 js的返回结果 是0.83,code 如下: var b = 0.825; ...
- C++程序在debug模式下遇到Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call问题。
今天遇到一个Access Violation的crash,只看crash call stack没有找到更多的线索,于是在debug模式下又跑了一遍,遇到了如下的一个debug的错误提示框: 这个是什么 ...
- [Python]round四舍五入精度缺失的解决
环境: os: win7 64bit python:2.7.5 32bit 对python四舍五入的解决方案 现象: 一般的四舍五入操作都是使用内置的round方法 In [14]: round ...
- OD: Memory Attach Technology - Off by One, Virtual Function in C++ & Heap Spray
Off by One 根据 Halvar Flake 在“Third Generation Exploitation”中的描述,漏洞利用技术依攻击难度从小到大分为三类: . 基础的栈溢出利用,可以利用 ...
- Round() 四舍五入 js银行家算法
首先问一下round(0.825,2) 返回的结果,大家猜一猜, 首先SQL server 返回的是 0.83 js的返回结果 是0.83,code 如下: var b = 0.825; ...
- overflow与underflow
是新近的firefox浏览器中支持overflow, underflow这两个事件,当某一元素的大小超出父元素的显示范围就会触发overflow事件,如果从超出显示再变回不超出的状态则触发underf ...
随机推荐
- 笔试算法题(04):实现 string & memcpy & strcpy & strlen
出题:请实现给定String的类定义: 分析:注意检查标准类构造注意事项: 解题: #include <stdio.h> #include <string.h> /** * 检 ...
- Layui框架 中table解决日期格式问题
使用templet自定义模板(详细查看官方文https://www.layui.com) 1.对Date的扩展,将 Date 转化为指定格式的String ,创建一个js文件: (dataForma ...
- 在git提交时忽略已提交过或从线上拉取下来但本地已修改的文件
一.忽略: git update-index --assume-unchanged [file-path] 命令中的file-path 就是需要忽略提价的文件的路径 例子: git update-in ...
- PHP:压缩 Zip
文章来源:http://www.cnblogs.com/hello-tl/p/7661222.html <?php # 文件字符集 header("Content-type: text ...
- windows下mysql 5.7版本中修改编码为utf-8的方法
方法如下 首先通过 show variables like 'character_set_%';查看mysql字符集情 默认编码为 latin1 然后关闭数据库 在mysql安装目录下找到my.ini ...
- stark组件之删除页面内容搭建(八)
删除页面没有太多的内容和功能 def del_view(self, request,pk,*args,**kwargs): """ 处理删除表弟 :param reque ...
- 关于SELECT 逻辑的执行顺序问题
不会有大多数人都和我一样的认为,是先进行的Where 剔除结果集,再进行Join的吧 SQL server 2014 逻辑执行标准: https://msdn.microsoft.com/en-us/ ...
- BNUOJ 3278 Candies
Candies Time Limit: 1500ms Memory Limit: 131072KB This problem will be judged on PKU. Original ID: 3 ...
- 九度oj 题目1054:字符串内排序
题目1054:字符串内排序 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:10985 解决:5869 题目描述: 输入一个字符串,长度小于等于200,然后将输出按字符顺序升序排序后的字符串 ...
- JavaEE JDBC 核心API
JDBC接口核心的API @author ixenos java.sql.* 和 javax.sql.* |- Driver接口: 表示java驱动程序接口.所有的具体的数据库厂商要来实现此接口 ...