The "decimal" Data Type

This section describes the 'decimal' data type for floating-point values. 'decimal' uses a 128-bit storage size.

Comparing with Java, C# has a very interesting new date type called: decimal.

The "decimal" data type for floating-point values with a storage size that doubles the storage size of the "double" data type. See the storage size and precision range comparisons with "float", "double" and "decimal":

The following code will show you this:

// Decimals.cs
// Copyright (c) 2006 HerongYang.com. All Rights Reserved.

class Decimals {
   public static void Main() {
      float f;
      double d;
      decimal m;
      f = 10.0f/3.0f;
      d = 10.0d/3.0d;
      m = 10.0m/3.0m;
      System.Console.WriteLine("Float 10/3 = {0}", f);
      System.Console.WriteLine("Double 10/3 = {0}", d);
      System.Console.WriteLine("Decimal 10/3 = {0}", m);
   }
}

Output:

Float 10/3 = 3.333333
Double 10/3 = 3.33333333333333
Decimal 10/3 = 3.3333333333333333333333333333

Table of Contents

 About This Book

 Introduction of C# (C Sharp)

 Data Type and Variables

 Logical Expressions and Conditional Statements

 Arrays and Loop Statements

Data Type Features

The "decimal" Data Type

 Simple Types Are "struct" Types

 Type System Unification

 Jagged Arrays

 Floating-Point Data Types

 Passing Parameters to Methods

 Execution Environment Class

 Visual C# 2010 Express Edition

 Class Features

 C# Compiler and Intermediate Language

 Compiling C# Source Code Files

 MSBuild - Microsoft Build Engine

 Memory Usages of Processes

 Multithreading in C#

 Async Feature from C# 5

 System.IO.FileInfo Class

 System.Diagnostics.FileVersionInfo Class

 WPF - Windows Presentation Foundation

 Partial Classes and Partial Methods

 Archived Tutorials

 References

 Full Version in PDF/ePUB