Use ToString() to format values : Number Format « Development Class « C# / C Sharp

C# / C Sharp
1. 2D Graphics
2. Class Interface
3. Collections Data Structure
4. Components
5. Data Types
6. Database ADO.net
7. Design Patterns
8. Development Class
9. Event
10. File Stream
11. Generics
12. GUI Windows Form
13. Language Basics
14. LINQ
15. Network
16. Office
17. Reflection
18. Regular Expressions
19. Security
20. Services Event
21. Thread
22. Web Services
23. Windows
24. XML
25. XML LINQ
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
C# / C Sharp » Development Class » Number FormatScreenshots 
Use ToString() to format values
Use ToString() to format values

/*
C#: The Complete Reference 
by Herbert Schildt 

Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/


// Use ToString() to format values. 
 
using System; 
 
public class ToStringDemo 
  public static void Main() { 
    double v = 17688.65849
    double v2 = 0.15
    int x = 21
  
    string str = v.ToString("F2")
    Console.WriteLine(str)
 
    str = v.ToString("N5")
    Console.WriteLine(str)
 
    str = v.ToString("e")
    Console.WriteLine(str)
 
    str = v.ToString("r")
    Console.WriteLine(str)
 
    str = v2.ToString("p")
    Console.WriteLine(str)
 
    str = x.ToString("X")
    Console.WriteLine(str)
 
    str = x.ToString("D12")
    Console.WriteLine(str)
 
    str = 189.99.ToString("C")
    Console.WriteLine(str)
  
}

           
       
Related examples in the same category
1. Format an enumerationFormat an enumeration
2. Use String.Format() to format a valueUse String.Format() to format a value
3. A closer look at Format()A closer look at Format()
4. Using custom formatsUsing custom formats
5. Numeric Formatting:Custom Format Strings:Decimal PointNumeric Formatting:Custom Format Strings:Decimal Point
6. Numeric Formatting:Custom Format Strings:Digit or Space PlaceholderNumeric Formatting:Custom Format Strings:Digit or Space Placeholder
7. Numeric Formatting:Custom Format Strings:Digit or Zero PlaceholderNumeric Formatting:Custom Format Strings:Digit or Zero Placeholder
8. Numeric Formatting:Custom Format Strings:Escapes and LiteralsNumeric Formatting:Custom Format Strings:Escapes and Literals
9. Numeric Formatting:Custom Format Strings:Exponential NotationNumeric Formatting:Custom Format Strings:Exponential Notation
10. Numeric Formatting:Custom Format Strings:Group SeparatorNumeric Formatting:Custom Format Strings:Group Separator
11. Numeric Formatting:Custom Format Strings:Number PrescalerNumeric Formatting:Custom Format Strings:Number Prescaler
12. Numeric Formatting:Custom Format Strings:Percent NotationNumeric Formatting:Custom Format Strings:Percent Notation
13. Numeric Formatting:Custom Format Strings:Section SeparatorNumeric Formatting:Custom Format Strings:Section Separator
14. Numeric Formatting:Standard Format Strings:CurrencyNumeric Formatting:Standard Format Strings:Currency
15. Numeric Formatting:Standard Format Strings:DecimalNumeric Formatting:Standard Format Strings:Decimal
16. Numeric Formatting:Standard Format Strings:Fixed-PointNumeric Formatting:Standard Format Strings:Fixed-Point
17. Numeric Formatting:Standard Format Strings:GeneralNumeric Formatting:Standard Format Strings:General
18. Numeric Formatting:Standard Format Strings:HexadecimalNumeric Formatting:Standard Format Strings:Hexadecimal
19. Numeric Formatting:Standard Format Strings:NumberNumeric Formatting:Standard Format Strings:Number
20. Numeric Formatting:Standard Format Strings:Scientific (Exponential)Numeric Formatting:Standard Format Strings:Scientific (Exponential)
21. Illustrates formatting numbersIllustrates formatting numbers
w___ww__.ja__v___a__2__s__.__c___o___m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.