Wednesday, January 27, 2010

Data Type Range: Floating-Point and Decimal Data Types

Another thing that confused me is the Floating-Point and Decimal Data Types. So this is again my reminder.

  • float - based on System.Single
    • 32-bit single-precision floating point number between -3.402832 x 1038 and -1.401298 / 1045 (for negative values) and between 1.401298 / 1045 and 3.402832 x 1038 (for positive values)
    • numeric literal - F or f. e.g. float price = 345.45F;
  • double - based on System.Double
    • 64-bit double-precision floating point number between -1.79769313486231570 x 10308 and -4.94065645841246544 / 10324 (for negative values) and between 4.94065645841246544 x 10324 and 1.79769313486231570 x 10308
    • numeric literal - D or d. e.g. double salary = 2500.50D;
  • decimal - based on System.Decimal
    • 128-bit number between -79,228,162,514,264,337,593,543,950,335 and 79,228,162,514,264,337,593,543,950,335 with no decimal places and between -7.9228162514264337593543950335 and 7.9228162514264337593543950335 with up to 28 decimal places
    • holds numbers of lesser range than floating points but with greater precision
    • numeric literal - M or m. e.g. decimal width = 3.68M;

More of c# literal could be found here.

No comments:

Post a Comment