本文介绍了如何删除小数而不舍入它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何取一个像0.6667这样的数字并删除小数位并使其成为0.66之类的数字。换句话说,我必须删除小数。
How do I take a number like maybe 0.6667 and remove the decimal place and making it a number like 0.66. In other words I have to remove the decimal.
推荐答案
DECLARE @decimal decimal(6, 6)
SET @decimal = 0.6667
--EASY WAY (with rounding)
DECLARE @decimal2 decimal(6,2)
SET @decimal2 = @decimal
PRINT @decimal2
--SEMI-EASY WAY (no rounding)
--Not dependable unless you have a set length for all the INPUT numbers
DECLARE @vchar_decimal varchar(4)
SET @vchar_decimal = CAST(@decimal as varchar(10))
PRINT @vchar_decimal
--HARD WAY (no rounding)
DECLARE @char_decimal varchar(MAX)
DECLARE @decimal_position int
DECLARE @decimal_output varchar(50)
SET @char_decimal = CAST(@decimal as varchar(MAX))
SET @decimal_position = CHARINDEX('.', @char_decimal)
SET @decimal_output = SUBSTRING(@char_decimal, 1, (@decimal_position + 2))
PRINT @decimal_output
希望这会有所帮助,
-Artificer GM
Hope this helps,
-Artificer GM
declare @DecimalVal Decimal(18,7)
set @DecimalVal=14.5267
select @DecimalVal
select CONVERT(DECIMAL(18,2),CAST(cast(@DecimalVal* 100 as int) as decimal (18, 2))/100)
这篇关于如何删除小数而不舍入它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!