十进制/单/ ......:使用哪种数字类型? [英] Decimal/Single/...: which Numeric-type to use?

查看:78
本文介绍了十进制/单/ ......:使用哪种数字类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我的VB.NET 2005

应用程序中的数字类型与SQL Server一起出现问题2000.


- 我首先在我的应用程序中使用Single,在我的数据库中使用Decimal。但是一个价值4.475的单身
被转换为一个带有值的十进制数。

4.4749999999999996D。所以在从数据库中插入并选择它之后我会获得另一个值而不是原来的价值!


- 所以我在我的应用程序中也使用了Decimal,但是现在我的所有数字都是

格式化所有小数:当我的值为1时,它显示1.0000。一个

的单值很好地反映为1,但十进制值显示整个

小数部分,即使它不需要。

我需要的是:用户只需要在需要时看到小数部分,并且

我的值必须相同(没有4.475到4.474999999999的更改)。


这似乎是一个简单而基本的需求,但我一直有麻烦

用它:-(


我应该做什么/用什么?我的应用程序中的另一个数值数据类型?我的数据库中的另一个

数据类型?


任何帮助/提示/链接/信息都会非常感激!


Thansk提前很多,


Pieter

解决方案

呃,这取决于

是你正在进行金融风格计算的计算

精度是一切吗?如果是这样的话,使用十进制。或者它们是科学计算

你有各种各样的数字需要不准确的给定

数字的数字? (例如,计算工程项目中的应力)

此案例使用Double。我不会使用Single,除非......它是一个leagacy应用程序

正在转换或者你有非常大的阵列并且内存紧张


不要担心格式化,这对于获得

数据来说是微不足道的,您可以稍后对其进行排序。


hth


guy


" Pieter"写道:



我在我的VB.NET 2005
应用程序中遇到了一些数字类型的麻烦,以及一个SQL Server 2000.

- 我首先在我的应用程序中使用Single,在我的数据库中使用Decimal。但是单值为4.475的单值被转换为具有值的十进制值4.4749999999999996D。因此,在从数据库中插入并选择后,我获得了比原始值更多的值!

- 所以我在我的应用程序中也使用了Decimal,但现在我所有的数字都是
使用所有小数格式化:当我的值为1时,它显示1.0000。
单值很好地响应1,但十进制值显示整个小数部分,即使它不需要。

我需要的是:用户只应在需要时看到小数部分,并且
我的值必须相同(没有4.475到4.474999999999的更改)。

这似乎是一个简单而基本的需求,但我只是继续遇到麻烦:/(

我该怎么办/使用?我的应用程序中的另一种数值数据类型?我的数据库中的另一种数据类型?

任何帮助/提示/链接/信息都将非常感谢!

提前许多人,

Pieter


精确度确实是一切。大部分时间都是价格,重量,

等等。所以必须准确。


我确实担心格式化,因为当我在文本框中显示小数值

时,它会显示小数点后面的所有零,我不知道不想它

做到这一点。特别是在某些情况下,它大部分时间都包含整个

数字(1,2,3,......),而且很少1.001等。所以我不希望用户

看到整个时间1.0000,2.0000,3.0000等。


基本上:我需要精确的精确度,但最后没有零。


我该怎么做?文本框上没有格式属性......


" guy" < gu*@discussions.microsoft.com>在留言中写道

news:52 ********************************** @ microsof t.com ...

呃,它取决于你正在进行金融风格计算的计算,其中精确度是一切吗?如果是这样,请使用Decimal。或者它们是科学计算
你有多种数字需要准确到一个
数字? (例如,计算工程项目中的应力)
在这种情况下使用Double。我不会使用Single,除非......它是一个leagacy应用程序
正在转换或你有真正的大阵列和紧张的内存

不要担心格式化,这是微不足道的
数据正确,你可以稍后解决。



家伙



< blockquote>查看Decimal.ToString的重载


这个可以帮助...

(这是帮助的在线版本)

http://msdn.microsoft.com/library/de...ringtopic3.asp


hth


guy


" Pieter"写道:

精确是一切。大多数时候它是价格,重量,高度等等所以它必须准确。

我确实担心格式化,因为当我显示小数值时
在文本框中,它显示小数点后面的所有零,我不想要它。
这样做。特别是在某些情况下,它包含大部分时间的整个数字(1,2,3,......),很少1.001等。所以我不希望用户看到它整个时间1.0000,2.0000,3.0000等基本上:我需要精确的精确度,但最后没有零。

我该怎么做?文本框中没有Format属性...

" guy" < gu*@discussions.microsoft.com>在消息中写道
新闻:52 ********************************** @ microsof t.com。 ..

呃,它取决于你正在进行金融风格计算的计算,其中精确度是什么?如果是这样,请使用Decimal。或者它们是科学计算
你有多种数字需要准确到一个
数字? (例如,计算工程项目中的应力)
在这种情况下使用Double。我不会使用Single,除非......它是一个leagacy应用程序
正在转换或你有真正的大阵列和紧张的内存

不要担心格式化,这是微不足道的
数据正确,你可以稍后解决。



家伙




Hi,

I''m having some troubles with my numeric-types in my VB.NET 2005
application, together with a SQL Server 2000.

- I first used Single in my application, and Decimal in my database. But a
Single with value 4.475 was converted to a Decimal with value
4.4749999999999996D. So after inserting and selecting it from the database I
got another value than the original!

- So I used also the Decimal in my application, but now all my numbers are
formatted with all the decimals: when my value is "1", it shows "1.0000". A
single value roudns it nicely to 1, but the decimal value shows the whole
decimal part, even when it isn''t needed.
What I need is: the users should only see the decimal part when needed, AND
my values have to be the same (no 4.475 to 4.474999999999 changements).

This seems such a simple and basic need, but I just keep having troubles
with it :-(

What should I do/use? Another numeric datatype in my application? Another
datatype in my Database??

Any help/hints/links/information would be really appreciated!

Thansk a lot in advance,

Pieter

解决方案

er, it depends
are the calculations that you are performing financial style calcs where
precision is everything? if so use Decimal. or are they scientific calcs
where you have a wide range of numbers that need ot be accurate to a a given
nummber of digits? (eg calculation of stresses in an engineering project) in
this case use Double. I wouldnt use Single unless... it is a leagacy app
being converted or you have REALLY big arrays and are tight on memory

dont worry about the formatting, that is trivial comapred with getting the
data right, you can sort it out later.

hth

guy

"Pieter" wrote:

Hi,

I''m having some troubles with my numeric-types in my VB.NET 2005
application, together with a SQL Server 2000.

- I first used Single in my application, and Decimal in my database. But a
Single with value 4.475 was converted to a Decimal with value
4.4749999999999996D. So after inserting and selecting it from the database I
got another value than the original!

- So I used also the Decimal in my application, but now all my numbers are
formatted with all the decimals: when my value is "1", it shows "1.0000". A
single value roudns it nicely to 1, but the decimal value shows the whole
decimal part, even when it isn''t needed.
What I need is: the users should only see the decimal part when needed, AND
my values have to be the same (no 4.475 to 4.474999999999 changements).

This seems such a simple and basic need, but I just keep having troubles
with it :-(

What should I do/use? Another numeric datatype in my application? Another
datatype in my Database??

Any help/hints/links/information would be really appreciated!

Thansk a lot in advance,

Pieter



Precision is indeed everything. Most of the time it are prices, weights,
heights etc. So it has to be exact.

And I do worry about the formatting, because when I show the decimal value
in a Textbox, it shows all the zeros after the decimal, and I don''t want it
to do it. Especially in some cases where it contains most of the time whole
numbers (1, 2, 3, ...) and rarely 1.001 etc. So I don''t want the user to be
seeing the whole time 1.0000, 2.0000, 3.0000, etc.

Basicly: I need exact precision, but without the zeros at the end.

How should I do that? there isn''t a Format-property on the textbox...

"guy" <gu*@discussions.microsoft.com> wrote in message
news:52**********************************@microsof t.com...

er, it depends
are the calculations that you are performing financial style calcs where
precision is everything? if so use Decimal. or are they scientific calcs
where you have a wide range of numbers that need ot be accurate to a a
given
nummber of digits? (eg calculation of stresses in an engineering project)
in
this case use Double. I wouldnt use Single unless... it is a leagacy app
being converted or you have REALLY big arrays and are tight on memory

dont worry about the formatting, that is trivial comapred with getting the
data right, you can sort it out later.

hth

guy



look at the overloads of Decimal.ToString

this one may help...
(it is the online version of Help)

http://msdn.microsoft.com/library/de...ringtopic3.asp

hth

guy

"Pieter" wrote:

Precision is indeed everything. Most of the time it are prices, weights,
heights etc. So it has to be exact.

And I do worry about the formatting, because when I show the decimal value
in a Textbox, it shows all the zeros after the decimal, and I don''t want it
to do it. Especially in some cases where it contains most of the time whole
numbers (1, 2, 3, ...) and rarely 1.001 etc. So I don''t want the user to be
seeing the whole time 1.0000, 2.0000, 3.0000, etc.

Basicly: I need exact precision, but without the zeros at the end.

How should I do that? there isn''t a Format-property on the textbox...

"guy" <gu*@discussions.microsoft.com> wrote in message
news:52**********************************@microsof t.com...

er, it depends
are the calculations that you are performing financial style calcs where
precision is everything? if so use Decimal. or are they scientific calcs
where you have a wide range of numbers that need ot be accurate to a a
given
nummber of digits? (eg calculation of stresses in an engineering project)
in
this case use Double. I wouldnt use Single unless... it is a leagacy app
being converted or you have REALLY big arrays and are tight on memory

dont worry about the formatting, that is trivial comapred with getting the
data right, you can sort it out later.

hth

guy




这篇关于十进制/单/ ......:使用哪种数字类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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