
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
Integer literals vs Floating point literals in C#
Integer Literals
An integer literal can be a decimal, or hexadecimal constant. A prefix specifies the base or radix: 0x or 0X for hexadecimal, and there is no prefix id for decimal. Here are some of the examples of integer literals −
10 // int 18u // unsigned int
Let’s use the above literal while declaring and initializing a variable −
// int int a =10;
We will now print the values −
Example
using System; namespace Demo { class Program { static void Main(string[] args) { // int int a =200; Console.WriteLine(a); } } }
Output
200
Floating-point Literal
A floating-point literal has an integer part, a decimal point, a fractional part, and an exponent part. You can represent floating point literals either in decimal form or exponential form.
The following are some of the examples of floating point literals −
4.89f 314159E-5F
While representing in decimal form, you must include the decimal point, the exponent, or both; and while representing using exponential form you must include the integer part, the fractional part, or both. The signed exponent is introduced by e or E.
Let us now print the floating point literals −
Example
using System; namespace Demo { class Program { static void Main(string[] args) { // float float a = 4.89f; Console.WriteLine(a); } } }
Output
4.89
- Related Articles
- What are floating point literals in C#?
- What is the difference between integer and floating point literals in Java?
- Object literals vs constructors in JavaScript
- What are integer literals in C#?
- Character constants vs String literals in C#
- Define integer literals as octal values in Java
- Type difference of character literals in C vs C++
- Literals in C#
- Literals in Java programming
- Boolean Literals in Java
- Compound Literals in C
- Octal literals in C
- Perl Special Literals
- What is the difference between character literals and string literals in Java?
- User Defined Literals in C++
