示例:
如果小数点后有两位以上的数字,则应截断。
我必须在存储过程中实现它。前端应用程序只有exe,无法更改。
答案 0 :(得分:2)
很明显,这属于“表示层”,但是如果您必须...
示例
Declare @YourTable table (Value decimal(16,6))
Insert Into @YourTable values
(10.00)
,(10.3)
,(10.53)
,(10.246)
Select *
,NewString = format(round(Value,2,1),'0.##')
From @YourTable
返回
Value NewString
10.000000 10
10.300000 10.3
10.530000 10.53
10.246000 10.24 -- Note not rounded to 10.25
答案 1 :(得分:0)
只需使用FORMAT
函数
declare @value float
set @value = 10.245
select format(@value,'0.0#') as formatted_value
将显示10.26
如果要截断,则速度更快:
select round(@value,2,1)
将显示10.25