在sql server数据库表中添加零到整数? [英] add zero to integer number in sql server database table ?

查看:61
本文介绍了在sql server数据库表中添加零到整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi




如何在sql server数据库表中为我的整数加零?



ex:



1.4我希望它显示为1.40?



请帮忙:)

解决方案

你没有。
就数字而言,
1.4与1.40相同 - 而且只有在它们出现时转换为字符串,以便向用户显示它们在输出中获得任何精度。这种演示应该在您的演示软件(c#,VB,C ++,...)而不是数据库中完成 - 因为数据库不需要知道您正在对它传递给您的数据做什么! br $> b $ b

但是......如果必须,可以在SQL中将其转换为小数并指定位数:

  DECLARE   @ N   FLOAT  
SET @ N = 1. 4

SELECT CONVERT DECIMAL 10 2 ), @ N


hi

how can i add zero to my integer number in sql server database table ?

ex:

1.4 i want it to appear as 1.40 ?

please help :)

解决方案

You don't.
1.4 is the same as 1.40 as far as numbers are concerned - and it's only when they get converted to strings for presentation to the user that they acquire any precision in the output. And that kind of presentation should be done in your presentation software (c#, VB, C++, ...) rather than at the database - because the database shouldn't need to know what you are doing with the data it passes you!

But...if you must, you can convert it to a decimal in SQL and specify the number of digits:

DECLARE @N FLOAT
SET @N=1.4

SELECT CONVERT(DECIMAL(10, 2), @N)


这篇关于在sql server数据库表中添加零到整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆