Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defining different types of numbers in C#

Tags:

You can define a number in various ways in C#,

1F // a float with the value 1 1L // a long with the value 1 1D // a double with the value 1 

personally I'm looking for which would a short, however to make the question a better reference for people, what are all the other post-fix's to number literals you can apply?

like image 328
Sekhat Avatar asked Nov 04 '08 17:11

Sekhat


People also ask

What are the different types of numbers in C?

The C language provides the four basic arithmetic type specifiers char, int, float and double, and the modifiers signed, unsigned, short, and long. The following table lists the permissible combinations in specifying a large set of storage size-specific declarations.

What are the 5 data types in C?

Most of the time, for small programs, we use the basic fundamental data types in C – int, char, float, and double. For more complex and huge amounts of data, we use derived types – array, structure, union, and pointer. Enumeration and void consist of enum and void, respectively.

What is data type explain different data types in C?

char: The most basic data type in C. It stores a single character and requires a single byte of memory in almost all compilers. int: As the name suggests, an int variable is used to store an integer. float: It is used to store decimal numbers (numbers with floating point value) with single precision.


2 Answers

Type        Suffix    .NET Framework Type                   ------------------------------------------------------------------------------------- decimal     M or m    System.Decimal double      D or d    System.Double float       F or f    System.Single int         [1]       System.Int32 long        L or l    System.Int64 

[1] When an integer literal has no suffix, its type is the first of these types in which its value can be represented: int, uint, long, ulong.

When an integer literal specifies only a U or u suffix, its type is the first of these types in which its value can be represnted: uint, ulong.

When an integer literal specifies only a L or l suffix, its type is the first of these types in which its value can be represnted: long, ulong.

When an integer literal specifies both a U or u and L or l suffix, its type is the first of these types in which its value can be represnted: ulong.

like image 139
Scott Dorman Avatar answered Nov 15 '22 16:11

Scott Dorman


Integer

Suffix - Description

none - first of int, uint, long and ulong

U or u - first of uint, ulong

L or l - first of long, ulong

UL, Ul, uL, ul, LU, Lu, lU, or lu - ulong

Real

Suffix - Description

none - double

F or f - float

D or d - double

M or m - decimal

like image 26
Skizz Avatar answered Nov 15 '22 17:11

Skizz