decimal
In this chapter you will learn:
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:
- Use the decimal type to compute a discount
- decimals and arithmetic operators
- Use the decimal type to compute the future value of an investment
Home » C# Tutorial » Decimal, Float, Double