如何确定要使用哪种通用十进制数据类型。 [英] How to determine which of the generic decimal datatypes to use.

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

问题描述

John Bentley:

INTRO

短语十进制数"在编程上下文中是不明确的。它可以

引用十进制数据类型或相关但单独的概念

十进制数。 十进制数有时用于从基数2数字,例如1111中区分基数10,例如15。在其他时间十进制

数字用于区分数字和整数。对于这个

帖子的其余部分,我只能使用通用十进制数和通用十进制数。或十进制数据类型

清晰度。


定义

通用十进制数:基数为10的数字,其中小数部分用
表示
位数。通用十进制数可以用几种

数据类型中的任何一种来实现,包括十进制数据类型,一个double,一个,一个字符串。


十进制数据类型: .Net(或其他编程语言)十进制数据类型。


问题

使用通用十进制数编程时,存在一些关键问题

考虑:


1如何舍入数字。

2如何确定使用哪种通用十进制数据类型:Single;

Double;或十进制

3确定两个通用十进制数是否相等。

4使用无法准确表示为通用小数的分数

数。


这些是相互关联的问题,但目前我对2感兴趣。


你想告诉我你的规则吗?在决定使用浮动

点数据类型(单和双)V时使用固定点/缩放整数数据类型

(十进制)?如果它有助于回答这个问题,那么请务必解决其他相关问题。虽然我会对那些与.NET有关的答案感兴趣,但我特别感兴趣的是一般的

数学/计算思想来决定选择。

John Bentley:
INTRO
The phrase "decimal number" within a programming context is ambiguous. It could
refer to the decimal datatype or the related but separate concept of a generic
decimal number. "Decimal Number" sometimes serves to distinguish Base 10
numbers, eg "15", from Base 2 numbers, Eg "1111". At other times "Decimal
Number" serves to differentiate a number from an integer. For the rest of this
post I shall only use either "Generic Decimal Number " or "decimal datatype" for
clarity.

DEFINTIONS
Generic Decimal Number: a base 10 number with a fractional part represented with
digits. A Generic Decimal Number may be implemented with any of several
datatypes including the decimal datatype, a double, a single, a string.

Decimal Datatype: the .Net (or other programming language) decimal datatype.

ISSUES
When programming with generic decimal numbers there are a few of key issues to
consider:

1 How to round a number.
2 How to determine which of the generic decimal datatypes to use: Single;
Double; or Decimal
3 Determine if two generic decimal numbers are equal.
4 Work with fractions that cannot be represented accurately as a generic decimal
numbers.

These are interrelated issues but for the moment I''m interested in 2.

Would you like to tell me the rules you use when deciding to use the floating
point datatypes (Single and Double) V the Fixed Point/Scaled Integer Datatype
(Decimal)? By all means address other related issues if it helps in the
answering of this question. Although I would be interested in answers that
relate to .NET specifially I''m interested more in the general
mathematical/computational ideas that govern the choice.

推荐答案

John Bentley< no ***** @ nowhere.com>写道:
John Bentley <no*****@nowhere.com> wrote:
这些是相互关联的问题,但目前我对2感兴趣。

你想告诉我你决定使用浮动时使用的规则吗?
点数据类型(单和双)V固定点/缩放整数数据类型
(十进制)?如果它有助于回答这个问题,请务必解决其他相关问题。虽然我会对与.NET有关的答案感兴趣,但我更感兴趣的是一般的
数学/计算思想来决定选择。
These are interrelated issues but for the moment I''m interested in 2.

Would you like to tell me the rules you use when deciding to use the floating
point datatypes (Single and Double) V the Fixed Point/Scaled Integer Datatype
(Decimal)? By all means address other related issues if it helps in the
answering of this question. Although I would be interested in answers that
relate to .NET specifially I''m interested more in the general
mathematical/computational ideas that govern the choice.


http://www.pobox.com/~skeet/csharp /floatingpoint.html 给出了浮点数的一些

的详细信息,以及关于何时使用什么的一些建议。这不完全是你所追求的,但希望你会发现它是有用的。


-

Jon Skeet - < sk *** @ pobox.com>
http ://www.pobox.com/~skeet/

如果回复小组,请不要给我发邮件



http://www.pobox.com/~skeet/csharp/floatingpoint.html gives some of the
details of floating point numbers, and some suggestions as to when to
use what. It''s not exactly what you were after, but hopefully you''ll
find it useful.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too


> http://www.pobox.com/~skeet/csharp/ floatingpoint.html 给出了一些
浮点数的详细信息,以及一些关于
何时使用什么的建议。这并不完全是你所追求的,但希望你会发现它很有用。
the details of floating point numbers, and some suggestions as to
when to
use what. It''s not exactly what you were after, but hopefully you''ll
find it useful.




Jon,这正是事物的类型我在追求。你的文章写得很好

。待机1或2天:我正在消化你在那里提出的问题。我会

有一些问题。感谢您发布它。



Jon, that is exactly the type of thing I was after. Yours is a well written
article. Standby 1 or 2 days: I am digesting the issues you raise there. I will
have some questions. Thanks for publishing it.


John Bentley< no ***** @ nowhere.com>写道:
John Bentley <no*****@nowhere.com> wrote:
http://www.pobox.com/~skeet/csharp/floatingpoint.html 给出了一些浮点数的详细信息,以及关于什么时候到的一些建议。
使用什么。这并不完全是你所追求的,但希望你会发现它很有用。
Jon,这正是我追求的那种东西。你的文章写得很好。
http://www.pobox.com/~skeet/csharp/floatingpoint.html gives some of
the details of floating point numbers, and some suggestions as to
when to
use what. It''s not exactly what you were after, but hopefully you''ll
find it useful.
Jon, that is exactly the type of thing I was after. Yours is a well written
article.




谢谢 - 你真好。

待机1或2天:我正在消化你在那里提出的问题。我会有一些问题。感谢您发布它。



Thanks - that''s very kind of you.
Standby 1 or 2 days: I am digesting the issues you raise there. I will
have some questions. Thanks for publishing it.




问题非常受欢迎 - 他们会建议我可以扩展的方式

这篇文章,一件事:)


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet/

如果回复小组,请不要给我发邮件



Questions are more than welcome - they''ll suggest ways I could expand
the article, for one thing :)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too


这篇关于如何确定要使用哪种通用十进制数据类型。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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