我需要存储并对货币价值进行一些基本计算(主要是乘法),比如
£0.00005756
,
£0.01
,
£0.000000000000123
0
在左侧,不太可能使用超过2位小数,但这是可能的。我遇到过的问题是当数字超过小数点后2位时。
我创建了一个测试表并插入了一些基本数据。不幸的是,它似乎不能存储非常小的数字。
注意:我创建了
money2
列为
[decimal](18, 4)
当我研究如何使用货币价值时,这似乎是推荐的。但是,我需要15位小数,这就是为什么
money1
存在。
CREATE TABLE [dbo].[MoneyTest](
[id] [int] IDENTITY(1,1) NOT NULL,
[money1] [decimal](18, 15) NULL,
[money2] [decimal](18, 4) NULL,
CONSTRAINT [PK_uMoneyTest] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
insert into moneytest
(money1, money2) values
(£0.01,£0.01)
insert into moneytest
(money1, money2) values
(£0.000000000000123,£0.000000000000123)
insert into moneytest
(money1, money2) values
(£0.00005756,£0.00005756)
select * from moneytest
id money1 money2
7 0.010000000000000 0.0100
8 0.000000000000000 0.0000
9 0.000100000000000 0.0001
不过,我期待着这些结果:
id money1 money2
7 0.010000000000000 0.0100
8 0.000000000000123 0.0000
9 0.000575600000000 0.0001
特别是,行id 9似乎向上舍入到1(小数点4处),而不是显示实际数字。我认为只有在使用浮点列估计数字时才会发生这种情况,小数点应该更准确?