SlideShare a Scribd company logo
1 of 2
Download to read offline
...015ProjectsMyNumberFormatsMyNumberFormatsProgram.cs 1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyNumberFormats
{
class Program
{
static void Main(string[] args)
{
// Declare Variables
double mynumber = new double();
Random myRnd = new Random();
// Initialise Variables
mynumber = 10000 * myRnd.NextDouble(); // 0 to 10000
// Print Results
Console.WriteLine($"The value is {mynumber}");
// Number Formats
Console.WriteLine($"The value is {mynumber.ToString("n")} (Number
Format)");
// Currency Format
Console.WriteLine($"The value is {mynumber.ToString("c")}
(Currency Format)");
// Scientific Formats
Console.WriteLine($"The value is {mynumber.ToString("e")}
(Scientific Format)");
Console.WriteLine($"The value is {mynumber.ToString("e2")}
(Scientific Format, 3 significant figures)" );
Console.WriteLine($"The value is {mynumber.ToString("e3")}
(Scientific Format, 4 significant figures)" );
// Fixed Formats
Console.WriteLine($"The value is {mynumber.ToString("f")} (Fixed
Format)");
Console.WriteLine($"The value is {mynumber.ToString("f3")} (Fixed
Format, 3 decimal places)"); // 3 decimal places
Console.WriteLine($"The value is {mynumber.ToString("f4")} (Fixed
Format, 4 decimal places)"); // 4 decimal places
// Percent Formats
Console.WriteLine($"The value is {mynumber.ToString("p")}
(Percent Format)");
Console.WriteLine($"The value is {mynumber.ToString("p1")}
(Percent Format, 1 decimal place)");
Console.WriteLine();
...015ProjectsMyNumberFormatsMyNumberFormatsProgram.cs 2
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Using String.Format
Console.WriteLine($"Using String Formats");
Console.WriteLine(String.Format($"The value is {mynumber:n}
(Number Format)"));
Console.WriteLine(String.Format($"The value is {mynumber:c}
(Currency Format)"));
Console.WriteLine(String.Format($"The value is {mynumber:e}
(Scientific Format)"));
Console.WriteLine(String.Format($"The value is {mynumber:e2}
(Scientific Format, 3 significant figures)" ));
Console.WriteLine(String.Format($"The value is {mynumber:e3}
(Scientific Format, 4 significant figures)" ));
Console.WriteLine(String.Format($"The value is {mynumber:f}
(Fixed Format)"));
Console.WriteLine(String.Format($"The value is {mynumber:f3}
(Fixed Format, 3 decimal places)")); // 3 decimal places
Console.WriteLine(String.Format($"The value is {mynumber:f4}
(Fixed Format, 4 decimal places)")); // 4 decimal places
Console.WriteLine(String.Format($"The value is {mynumber:p}
(Percent Format)"));
Console.WriteLine(String.Format($"The value is {mynumber:p1}
(Percent Format, 1 decimal place)"));
}
}
}

More Related Content

What's hot

Linked list imp of list
Linked list imp of listLinked list imp of list
Linked list imp of listElavarasi K
 
Concatenation of two strings using class in c++
Concatenation of two strings using class in c++Concatenation of two strings using class in c++
Concatenation of two strings using class in c++Swarup Boro
 
Bcsl 033 data and file structures lab s2-1
Bcsl 033 data and file structures lab s2-1Bcsl 033 data and file structures lab s2-1
Bcsl 033 data and file structures lab s2-1Dr. Loganathan R
 
Import data from csv excel file and export to xml excel file in c programming
Import data from csv excel file and export to xml excel file in c programmingImport data from csv excel file and export to xml excel file in c programming
Import data from csv excel file and export to xml excel file in c programmingSalar Delavar Qashqai
 
The Truth About Lambdas in PHP
The Truth About Lambdas in PHPThe Truth About Lambdas in PHP
The Truth About Lambdas in PHPSharon Levy
 
How to send a mail from utl smtp or from back end
How to send a mail from utl smtp or from back endHow to send a mail from utl smtp or from back end
How to send a mail from utl smtp or from back endManju Nath
 
Understanding storage class using nm
Understanding storage class using nmUnderstanding storage class using nm
Understanding storage class using nmmohamed sikander
 
Program to illustrate Switch, Goto and Exit statements.
Program to illustrate Switch, Goto and  Exit statements.Program to illustrate Switch, Goto and  Exit statements.
Program to illustrate Switch, Goto and Exit statements.harman kaur
 
Bcsl 033 data and file structures lab s2-2
Bcsl 033 data and file structures lab s2-2Bcsl 033 data and file structures lab s2-2
Bcsl 033 data and file structures lab s2-2Dr. Loganathan R
 
Auto increment number
Auto increment numberAuto increment number
Auto increment numbergayatri raval
 
Bcsl 033 data and file structures lab s1-3
Bcsl 033 data and file structures lab s1-3Bcsl 033 data and file structures lab s1-3
Bcsl 033 data and file structures lab s1-3Dr. Loganathan R
 
Bcsl 033 data and file structures lab s2-3
Bcsl 033 data and file structures lab s2-3Bcsl 033 data and file structures lab s2-3
Bcsl 033 data and file structures lab s2-3Dr. Loganathan R
 

What's hot (20)

Linked list imp of list
Linked list imp of listLinked list imp of list
Linked list imp of list
 
Concatenation of two strings using class in c++
Concatenation of two strings using class in c++Concatenation of two strings using class in c++
Concatenation of two strings using class in c++
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
Bcsl 033 data and file structures lab s2-1
Bcsl 033 data and file structures lab s2-1Bcsl 033 data and file structures lab s2-1
Bcsl 033 data and file structures lab s2-1
 
Import data from csv excel file and export to xml excel file in c programming
Import data from csv excel file and export to xml excel file in c programmingImport data from csv excel file and export to xml excel file in c programming
Import data from csv excel file and export to xml excel file in c programming
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
The Truth About Lambdas in PHP
The Truth About Lambdas in PHPThe Truth About Lambdas in PHP
The Truth About Lambdas in PHP
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
How to send a mail from utl smtp or from back end
How to send a mail from utl smtp or from back endHow to send a mail from utl smtp or from back end
How to send a mail from utl smtp or from back end
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
Understanding storage class using nm
Understanding storage class using nmUnderstanding storage class using nm
Understanding storage class using nm
 
Program to illustrate Switch, Goto and Exit statements.
Program to illustrate Switch, Goto and  Exit statements.Program to illustrate Switch, Goto and  Exit statements.
Program to illustrate Switch, Goto and Exit statements.
 
Bcsl 033 data and file structures lab s2-2
Bcsl 033 data and file structures lab s2-2Bcsl 033 data and file structures lab s2-2
Bcsl 033 data and file structures lab s2-2
 
Auto increment number
Auto increment numberAuto increment number
Auto increment number
 
Final ds record
Final ds recordFinal ds record
Final ds record
 
Bcsl 033 data and file structures lab s1-3
Bcsl 033 data and file structures lab s1-3Bcsl 033 data and file structures lab s1-3
Bcsl 033 data and file structures lab s1-3
 
Python program
Python programPython program
Python program
 
Bcsl 033 data and file structures lab s2-3
Bcsl 033 data and file structures lab s2-3Bcsl 033 data and file structures lab s2-3
Bcsl 033 data and file structures lab s2-3
 
Jva
Jva Jva
Jva
 

Similar to Listing for MyNumberFormats

Similar to Listing for MyNumberFormats (20)

Listing for TryLambdaExpressions
Listing for TryLambdaExpressionsListing for TryLambdaExpressions
Listing for TryLambdaExpressions
 
Mpesa_C# (2)
Mpesa_C# (2)Mpesa_C# (2)
Mpesa_C# (2)
 
Visula C# Programming Lecture 2
Visula C# Programming Lecture 2Visula C# Programming Lecture 2
Visula C# Programming Lecture 2
 
P/Invoke - Interoperability of C++ and C#
P/Invoke - Interoperability of C++ and C#P/Invoke - Interoperability of C++ and C#
P/Invoke - Interoperability of C++ and C#
 
Console programms
Console programmsConsole programms
Console programms
 
keyword
keywordkeyword
keyword
 
keyword
keywordkeyword
keyword
 
R Language
R LanguageR Language
R Language
 
L03vars
L03varsL03vars
L03vars
 
CSharp Presentation
CSharp PresentationCSharp Presentation
CSharp Presentation
 
SIMPLE C PROGRAMS - SARASWATHI RAMALINGAM
SIMPLE C PROGRAMS - SARASWATHI RAMALINGAMSIMPLE C PROGRAMS - SARASWATHI RAMALINGAM
SIMPLE C PROGRAMS - SARASWATHI RAMALINGAM
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
 
C# Lab Programs.pdf
C# Lab Programs.pdfC# Lab Programs.pdf
C# Lab Programs.pdf
 
C# Lab Programs.pdf
C# Lab Programs.pdfC# Lab Programs.pdf
C# Lab Programs.pdf
 
C programming 28 program
C programming 28 programC programming 28 program
C programming 28 program
 
C# console applications.docx
C# console applications.docxC# console applications.docx
C# console applications.docx
 
Net practicals lab mannual
Net practicals lab mannualNet practicals lab mannual
Net practicals lab mannual
 
Intake 37 linq2
Intake 37 linq2Intake 37 linq2
Intake 37 linq2
 
Unit-IV.pptx
Unit-IV.pptxUnit-IV.pptx
Unit-IV.pptx
 
Intake 38 data access 3
Intake 38 data access 3Intake 38 data access 3
Intake 38 data access 3
 

Listing for MyNumberFormats

  • 1. ...015ProjectsMyNumberFormatsMyNumberFormatsProgram.cs 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MyNumberFormats { class Program { static void Main(string[] args) { // Declare Variables double mynumber = new double(); Random myRnd = new Random(); // Initialise Variables mynumber = 10000 * myRnd.NextDouble(); // 0 to 10000 // Print Results Console.WriteLine($"The value is {mynumber}"); // Number Formats Console.WriteLine($"The value is {mynumber.ToString("n")} (Number Format)"); // Currency Format Console.WriteLine($"The value is {mynumber.ToString("c")} (Currency Format)"); // Scientific Formats Console.WriteLine($"The value is {mynumber.ToString("e")} (Scientific Format)"); Console.WriteLine($"The value is {mynumber.ToString("e2")} (Scientific Format, 3 significant figures)" ); Console.WriteLine($"The value is {mynumber.ToString("e3")} (Scientific Format, 4 significant figures)" ); // Fixed Formats Console.WriteLine($"The value is {mynumber.ToString("f")} (Fixed Format)"); Console.WriteLine($"The value is {mynumber.ToString("f3")} (Fixed Format, 3 decimal places)"); // 3 decimal places Console.WriteLine($"The value is {mynumber.ToString("f4")} (Fixed Format, 4 decimal places)"); // 4 decimal places // Percent Formats Console.WriteLine($"The value is {mynumber.ToString("p")} (Percent Format)"); Console.WriteLine($"The value is {mynumber.ToString("p1")} (Percent Format, 1 decimal place)"); Console.WriteLine();
  • 2. ...015ProjectsMyNumberFormatsMyNumberFormatsProgram.cs 2 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 // Using String.Format Console.WriteLine($"Using String Formats"); Console.WriteLine(String.Format($"The value is {mynumber:n} (Number Format)")); Console.WriteLine(String.Format($"The value is {mynumber:c} (Currency Format)")); Console.WriteLine(String.Format($"The value is {mynumber:e} (Scientific Format)")); Console.WriteLine(String.Format($"The value is {mynumber:e2} (Scientific Format, 3 significant figures)" )); Console.WriteLine(String.Format($"The value is {mynumber:e3} (Scientific Format, 4 significant figures)" )); Console.WriteLine(String.Format($"The value is {mynumber:f} (Fixed Format)")); Console.WriteLine(String.Format($"The value is {mynumber:f3} (Fixed Format, 3 decimal places)")); // 3 decimal places Console.WriteLine(String.Format($"The value is {mynumber:f4} (Fixed Format, 4 decimal places)")); // 4 decimal places Console.WriteLine(String.Format($"The value is {mynumber:p} (Percent Format)")); Console.WriteLine(String.Format($"The value is {mynumber:p1} (Percent Format, 1 decimal place)")); } } }