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 ...
随机推荐
- vue 中动画配置
<transition name="fade"> <router-view ></router-view> </transition& ...
- CF508E Arthur and Brackets
题目大意:给出n对括号,并给出每对括号距离的范围.问能否找到这样一个序列. 题解:好多人都用贪心.这么好的题为什么不搜一发呢? 注意:千万不要在dfs里面更新答案. 代码: #include<c ...
- 把wav文件等时长切割
ffmpeg -i somefile.mp3 -f segment -segment_time 1800 -c copy out%03d.mp3 segment_time 是切割时长,单位秒
- 语法,if,while循环,for循环
目录 一.语法 二.while循环 三.for循环 一.语法 if: if判断其实是在模拟人做判断.就是说如果这样干什么,如果那样干什么.对于ATM系统而言,则需要判断你的账号密码的正确性. if 条 ...
- LeetCode 123. Best Time to Buy and Sell Stock III (stock problem)
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- [luoguP1328] 生活大爆炸版石头剪刀布(模拟)
传送门 虽然是模拟,但是我们可以用矩阵保存结果,来是其更加简便. ——代码 #include <cstdio> #include <iostream> ][] = {{, , ...
- 元祖、hash了解、字典、集合
元祖: 元组跟列表差不多,也是存一组数,只是它一旦创建,便不能再修改,所以又叫只读列表. 创建: names = ('neo', 'mike', 'eric') 特性: # 1.可存放多个值 # 2. ...
- Quartz进一步学习与使用
一.再思考 了解Quartz.NET的基本使用方法了.但如果想方便的知道某个作业执行情况,需要暂停,启动等操作行为,这时候就需要个Job管理的界面,如何才能达到我们想到的效果,查看相关Quartz.n ...
- 创建Django项目(七)——表单
2013-08-15 19:43:01| 1.URL配置和视图 "blog\urls.py"文件中:添加url(r'write_article/$', 'write ...
- Servlet实现国际化
以下内容引用自http://wiki.jikexueyuan.com/project/servlet/internationalization.html: 三个重要术语: 国际化(i18n):这意味着 ...