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

int, float, double, decimal की जानकारी

int, float, double, और decimal अलग-अलग तरह के numbers के लिए boxes हैं: whole numbers, और अलग-अलग levels of precision वाले decimal points वाले numbers। पैसों के लिए decimal चुनें, जैसे सटीकता मायने रखने पर एक बारीक ruler चुनना।
Syntax
csharp
int wholeNumber = 30;
float singleValue = 36.6f;
double doubleValue = 12345.6789;
decimal money = 19.99m;

int, float, double, decimal

int whole numbers store करता है, float और double approximate binary floating-point numbers store करते हैं, और decimal base-10 numbers को सटीक रूप से store करता है — पैसों के लिए आदर्श।

double floating-point literals के लिए default है; float को f suffix चाहिए और decimal को m suffix चाहिए। सही numeric type चुनना सूक्ष्म rounding bugs से बचाता है।

Note: floating-point rounding errors से बचने के लिए currency calculations के लिए decimal का उपयोग करें।

उदाहरण: 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. #}
आम गलतियां
  1. float f = 3.14; लिखना, जो fail होता है क्योंकि 3.14 एक double है; 3.14f का उपयोग करें।
  2. पैसों के लिए double का उपयोग करना और rounding errors पाना, जबकि decimal currency के लिए है।
  3. 5 / 2 जैसे दो ints को divide करना और 2.5 की उम्मीद करना, जबकि integer division 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.