Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
428 views
in Technique[技术] by (71.8m points)

c# - 十进制与双精度! -应该使用哪一个?何时使用? [重复](decimal vs double! - Which one should I use and when? [duplicate])

This question already has an answer here:

(这个问题已经在这里有了答案:)

I keep seeing people using doubles in C#.

(我一直看到人们在C#中使用双打。)

I know I read somewhere that doubles sometimes lose precision.

(我知道我在某个地方读过一些内容,有时会失去精度。)

My question is when should a use a double and when should I use a decimal type?

(我的问题是什么时候应该使用双精度型,什么时候应该使用十进制型?)

Which type is suitable for money computations?

(哪种类型适合货币计算?)

(ie. greater than $100 million)

((即超过1亿美元))

  ask by Soni Ali translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

For money, always decimal.

(为了钱, 总是十进制。)

It's why it was created.

(这就是为什么它被创建。)

If numbers must add up correctly or balance, use decimal.

(如果数字必须正确加总或保持平衡,请使用十进制。)

This includes any financial storage or calculations, scores, or other numbers that people might do by hand.

(这包括人们可能手工进行的任何财务存储或计算,分数或其他数字。)

If the exact value of numbers is not important, use double for speed.

(如果数字的确切值不重要,请使用double作为速度。)

This includes graphics, physics or other physical sciences computations where there is already a "number of significant digits".

(这包括图形,物理学或其他物理科学计算,其中已经有“有效位数”。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...