Current area: HOME -> Blogs -> pheaven's Blog

The Official Programmer's Heaven Blog

The blog where the Programmer's Heaven team post stuff.
Float, Double and Decimal: do you know the differences?
Posted on Tuesday, March 11, 2008 at 3:17 AM
There are a number of data types available in the .Net framework for storing numbers with fractional parts. They are each appropriate for different situations, and using the wrong one can lead to errors in calculations.

Thinking About Accuracy

In some applications, you require that calculations involving numbers with fractional parts are exact. Examples of this are in financial applications, where losing the odd cent here and there in a calculation is unacceptable. Customers expect their accounts to be completely accurate, not to mention the tax man.

In other applications, you don't care about exact results, but you are interested in having an answer that is correct to a certain number of significant digits. This is the case in experimental physics, for example. When you make a measurement of something, you can only measure it as accurately as your equipment will allow you. Therefore, you have an inherent error in that value already, which is going to cascade through any calculations you do with it. This means that while your computed answer may be 5.1826, you may know that the values this answer was calculated from were only accurate to three significant digits, and so the last two digits in this result (the 0.0026) don't matter. If there is a computational error in them, so be it - it's not going to hurt us.

Read More

Subscribe

RSS Feed RSS Feed

By Tag

.NET Algorithm alpha five C# C# 3.0 DLinq Higher Order Programming Java Lambda Expressions Linq Linux MySQL Performance Perl Programming SSH Test Driven Develoment Testing Threading UNIX

By Month

April 2008
March 2008
February 2008
January 2008
December 2007
November 2007
October 2007

Help

Check out the Blog FAQ.


Sponsored links

Virtual File System SDK
Create your own file systems in Windows and .NET applications
PureCM Software Configuration Management
Version control and integrated issue tracking - powerful and easy to use. Get your FREE trial now!
Software Localization Tool Sisulizer
Localize DotNet, C++ Builder, Delphi, C/C++, Visual Basic & Java apps & html help. Try Sisulizer now
Attend WINDOWS EMBEDDED ACCELERATION WORKSHOPS
Are you ready to learn how you can bring your next-generation embedded device to market faster?
Delphi Localization Tool Sisulizer (WYSIWYG)
Create multilingual Delphi apps in three simple steps. Localize XML, HTML Help ... Try Sisulizer now


Newsletter | Submit Content | About | Advertising | Awards | Contact Us | Link to us |
© 1996-2008 Community Networks Ltd All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Synchron Data - .NET development.