if object_id('ta')is not null drop table ta create table ta(Inventory varchar(12),Rate1 decimal(6,2),Rate2 decimal(6,2)) insert ta select 'B1',0.5,-1.5select * from taInventory Rate1 Rate2 ------------ -------- -------- B1 .50 -1.50(所影响的行数为 1 行)
--2005测试可以 if object_id('ta')is not null drop table ta create table ta(Inventory varchar(12),Rate1 decimal(6,2),Rate2 decimal(6,2)) insert ta select 'B1',-0.5,-1.5select * from ta /*Inventory Rate1 Rate2 ------------ --------------------------------------- --------------------------------------- B1 -0.50 -1.50(1 行受影响)*/
--2005测试可以 if object_id('ta')is not null drop table ta create table ta(Inventory varchar(12),Rate1 decimal(6,2),Rate2 decimal(6,2)) insert ta select 'B1',-0.5,-1.5 select * from ta /*Inventory Rate1 Rate2 ------------ --------------------------------------- --------------------------------------- B1 -0.50 -1.50 (1 行受影响) */
if object_id('ta')is not null drop table ta
create table ta(Inventory varchar(12),Rate1 decimal(6,2),Rate2 decimal(6,2)) insert ta select 'B1',0.5,-1.5select * from taInventory Rate1 Rate2
------------ -------- --------
B1 .50 -1.50(所影响的行数为 1 行)
float,real,decimal(18, 2)Test1 Test2 Test3
-0.5 -0.5 -0.50
if object_id('ta')is not null drop table ta
create table ta(Inventory varchar(12),Rate1 decimal(6,2),Rate2 decimal(6,2)) insert ta select 'B1',-0.5,-1.5select * from ta
/*Inventory Rate1 Rate2
------------ --------------------------------------- ---------------------------------------
B1 -0.50 -1.50(1 行受影响)*/
if object_id('ta')is not null drop table ta
create table ta(Inventory varchar(12),Rate1 decimal(6,2),Rate2 decimal(6,2)) insert ta select 'B1',-0.5,-1.5 select * from ta
/*Inventory Rate1 Rate2
------------ --------------------------------------- ---------------------------------------
B1 -0.50 -1.50 (1 行受影响) */
显示不出来0
你可以这么做 出现这个0 不需要转换
一个呢是 前台处理
还有嘛 就是 控制面板->区域语言设置->格式->自定义格式->数字->零起始选择下酒OK
varchar类型应该可以存放的!
set @a = -0.5
select cast(@a as varchar(12)) --显示 -0.5前面有人说用varchar,如果要计算怎么办?比如加减法,要执行sum等统计怎么办?....
为了个显示格式而改变数据类型,舍本逐末
set @num=-0.5
select @num
返回结果
---------------------------------------
-0.50(1 行受影响)
注意,存贮与显示是两回事。
如何显示是前台程序关心的事。