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

int, float, double, decimal

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);
    }
}
🔒

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.