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 ...
随机推荐
- java常见日期格式转换以及日期的获取
package com.test.TestBoot.SingleModel;import java.text.SimpleDateFormat;import java.util.Date;public ...
- ubuntu 16.04 数据库mysql安装与管理
1.安装mysql的客户端与服务器端 $>sudo apt-get install mysql-server mysql-client 2.管理服务 1.启动 $>sudo service ...
- assert.fail()详解
assert.fail(actual, expected, message, operator) 抛出一个 AssertionError.如果 message 是假值,错误信息会被设置为被 opera ...
- HTML、CSS常用技巧
一.HTML 在介绍HTML之前,我们先看一下HTML的文档树结构,主要包括哪些: (一).头部标签 1,Doctype Doctype告诉浏览器使用什么样的HTML或XHTML规范来解析HTML文档 ...
- CodeForces 221D Little Elephant and Array
Little Elephant and Array Time Limit: 4000ms Memory Limit: 262144KB This problem will be judged on C ...
- 用PowerPoint中的VB实现课件中的智能交互
http://www.duxiushan.net/index.asp?xAction=xReadNews&NewsID=294 我们使用PPT的目的只有一个,即更好地达成“沟通.演说.汇报.讲 ...
- chrome webstore
chrome webstore https://chrome.google.com/webstore/detail/set-character-encoding/bpojelgakakmcfmjfil ...
- acm 一年总结
首先是大一的一段简短历史,和其他人不太一样,刚上大一的我等于是刚刚接触电脑,开始下载程序啦,安装系统了,电脑出个小问题啦自己都不会解决,然后大一还开了一门叫做c语言的课程,顿时傻逼了,当时也不用功,大 ...
- 南邮CTF密码学,mixed_base64
# -*- coding:utf-8 -*- from base64 import * flag = open("code.txt").readline() # 读取密文 for ...
- Being a Good Boy in Spring Festival 博弈论 Nim博弈
易游戏雷火盘古校园招聘开始! kiki's game Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 40000/10000 K (Ja ...