← Back to C# Course | Chapter 2: Variables & Types | Lesson 2 of 7

int, float, double, decimal

int, float, double, and decimal are boxes for numbers of different kinds: whole numbers, and numbers with decimal points at different levels of precision. Choose decimal for money, like picking a fine ruler when exactness matters.
Syntax
csharp
int wholeNumber = 30;
float singleValue = 36.6f;
double doubleValue = 12345.6789;
decimal money = 19.99m;

int, float, double, decimal

int stores whole numbers, float and double store approximate binary floating-point numbers, and decimal stores base-10 numbers precisely — ideal for money.

double is the default for floating-point literals; float needs an f suffix and decimal needs an m suffix. Choosing the right numeric type avoids subtle rounding bugs.

Note: Use decimal for currency calculations to avoid floating-point rounding errors.

Example: int, float, double, decimal

markup
using System;

class Program
{
    static void Main(string[] args)
    {
        int age = 30;
        float temperature = 36.6f;
        double distance = 12345.6789;
        decimal price = 19.99m;

        Console.WriteLine(age);
        Console.WriteLine(temperature);
        Console.WriteLine(distance);
        Console.WriteLine(price);
    }
}
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Writing float f = 3.14;, which fails because 3.14 is a double; use 3.14f.
  2. Using double for money and getting rounding errors, when decimal is meant for currency.
  3. Dividing two ints like 5 / 2 and expecting 2.5, when integer division gives 2.
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.