int, float, double, decimal की जानकारी
int, float, double, और decimal अलग-अलग तरह के numbers के लिए boxes हैं: whole numbers, और अलग-अलग levels of precision वाले decimal points वाले numbers। पैसों के लिए decimal चुनें, जैसे सटीकता मायने रखने पर एक बारीक ruler चुनना।
In this page:
Syntax
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
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);
}
}
Login to try C/C++/Java/PHP code in the editor
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. #}
आम गलतियां
float f = 3.14;लिखना, जो fail होता है क्योंकि3.14एकdoubleहै;3.14fका उपयोग करें।- पैसों के लिए
doubleका उपयोग करना और rounding errors पाना, जबकिdecimalcurrency के लिए है। 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: