Float, Double, and Decimal in C#

Comparison of Float, Double, Decimal in C# (SO)

Name Digits Bits Precision/Accuracy Speed
Float 7 digits 32 bit lower faster
Double 15-16 digits 64 bit lower faster
Decimal 28-29 significant digits 128 bit higher slower

float flt = 1F/3;
double db = 1D/3;

decimal dcm = 1M/3;

var equal = db == dcm; //Needs a cast
var equal = db == flt; //Does not need a cast

Leave a Reply

Your email address will not be published. Required fields are marked *

5 + six =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>