Difference Between Decimal, Float and Double in Microsoft.Net

Written by: Destiny Idika

Reading time:
Published 3 Years Ago On Wednesday, November 17, 2021
542 Views



In this article we will learn the Difference between decimal, float and double in .NET

  1. Float - 7 digits (32 bit)
  2. Double-15-16 digits (64 bit)
  3. Decimal -28-29 significant digits (128 bit)
Decimals have much higher precision and are usually used within financial applications that require a high degree of accuracy. Decimals are much slower (up to 20X times in some tests) than a double/float.
Decimals and Floats/Doubles cannot be compared without the use of an Implicit cast whereas Floats and Doubles can. Decimals also allow the encoding or trailing zeros.
Example
float flt = 1F/3;
double dbl = 1D/3;
decimal dcm = 1M/3;
Console.WriteLine("float: {0} double: {1} decimal: {2}", flt, dbl, dcm);


Result
float: 0.3333333
double: 0.333333333333333
decimal: 0.333333333333333333333333333

Decimal 128 bit (28-29 significant digits) In case of financial applications it is better to use Decimal types because it gives you a high level of accuracy and easy to avoid rounding errors.
Use decimal for non-integer math where precision is needed (e.g. money and currency)
Double 64 bit (15-16 digits) Double Types are probably the most normally used data type for real values, except handling money. Use double for non-integer math where the most precise answer isn't necessary.
Float 32 bit (7 digits) It is used mostly in graphic libraries because very high demands for processing powers, also used in situations that can endure rounding errors.

Please note the following points
  • Decimals are much slower than a double/float.
  • Decimals and Floats/Doubles cannot be compared without a cast; Whereas Floats and Doubles can.
  • Decimals also allow the encoding or trailing zeros.



The need for a top business owner or organization to have a professional, scalable, Fast, Optimized,Efficient, Very Secured web application (website) can never be over emphasized.
However, With this great tool (Web Application) Business Owners will definitely and Undoubtedly solidify their online presence, improve their Search Engine ranking, eliminate the likelihood of Missing out on search engine queries / results by prospective clients whom may search for a business like theirs on search engines like Bing and google, stay toe to toe with Compititors who already have a web application etc.
Read Now Top 15 Reasosns why you need a website for your Business
You don’t need to do all of these alone, We got you covered!! Contact us now your satisfaction is always our priority. price definitely won't be a problem.

Thanks for reading



30 Names Of God Alongside their Meaning And Bible Verse Reference

What Are Brute-Force Attacks | How to Protect Yourself against Brute-Force Attacks