decimal

In this chapter you will learn:

  1. decimal type
  2. decimal literials

Declare decimal variable

decimal is intended for use in monetary calculations. It utilizes 128 bits to represent values within the range 1E-28 to 7.9E+28. decimal eliminates the rounding errors caused by the normal floating-point data type.

The following code creates a decimal by specifying a Literal decimal,

class MainClass//from  j av a2 s  .c o  m
{
  static void Main()
  {

    System.Console.WriteLine(1.618m);
  }
}

decimal literials

using System;/*j  a v a 2  s.com*/

class Class1
{
  static void Main(string[] args)
  {
           decimal f;
           f = 999999999.123456789123456789123456789m;
           Console.WriteLine( "{0}", f );
  }
}

Decimal implements the following interfaces:

  • IComparable
  • IConvertible
  • IFormattable

Next chapter...

What you will learn in the next chapter:

  1. Use the decimal type to compute a discount
  2. decimals and arithmetic operators
  3. Use the decimal type to compute the future value of an investment
Home » C# Tutorial » Decimal, Float, Double
decimal
decimal calculation
decimal creation
decimal values
decimal flooring and ceiling
decimal conversion
Decimal parse
decimal format
decimal round
double
double type
Predefined double values
double infinit value
Calculation with double value
Parse string to double value
double value format
double vs decimal
Floating-Point Types
float constant value
float calculation
Parse string to float
float format