且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在sql server数据库表中添加零到整数?

更新时间:2023-02-07 11:33:47

你没有。
就数字而言,
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)