当前位置:网站首页>C string format (decimal point retention / decimal conversion, etc.)
C string format (decimal point retention / decimal conversion, etc.)
2022-07-03 14:48:00 【Jack1009HF】
C# string format ( The decimal point is reserved / Base conversion, etc )
stay C# Development process , It is often necessary to format and display numbers . Summarizes several common formats and implementation methods .
Format specification
1. Common format character
C currency
F Keep decimal places
G routine
N The number
E Scientific type
D Decimal system
X Hexadecimal
2.Convert.ToString(int val,int toBase) Hexadecimal conversion
You can convert numbers into string formats with different hexadecimal values
Be careful :toBase In parameter format , Can only be 2、8、10、16
Usage examples
static void Main(string[] args)
{
// Common format specifiers
Console.WriteLine(" currency :" +6.6.ToString("C")); // currency
Console.WriteLine(" decimal :" +6.6.ToString("F2")); // Fixed decimal point
Console.WriteLine(" routine :" +6.6.ToString("G")); // routine
Console.WriteLine(" The number :" +6.6.ToString("N")); // The number
Console.WriteLine(" science :" + 66.ToString("E")); // Scientific type
// Common format specifier base conversion
Console.WriteLine("10 Base number :" + 666.ToString("D")); // Decimal system
Console.WriteLine("16 Base number :" + 66666.ToString("X")); // Hexadecimal
//Convert.ToString(int val,int toBase) Hexadecimal conversion
Console.WriteLine(" Binary system :" + Convert.ToString(66, 2)); // Binary system
Console.WriteLine(" octal :" + Convert.ToString(66, 8)); // octal
Console.WriteLine(" Decimal system :" + Convert.ToString(66, 10)); // Decimal system
Console.WriteLine(" Hexadecimal :" + Convert.ToString(66, 16));// Hexadecimal
Console.ReadLine();
}
Output

( It's not easy for new people to create , Reprint please indicate the source )
边栏推荐
猜你喜欢
![[ue4] geometry drawing pipeline](/img/30/9fcf83a665043fe57389d44c2e16a8.jpg)
[ue4] geometry drawing pipeline

Creation of data table of Doris' learning notes

Puzzle (016.4) domino effect

puzzle(016.3)千丝万缕

Sword finger offer 28 Symmetric binary tree

Zzuli:1053 sine function

Solve the problem that PR cannot be installed on win10 system. Pr2021 version -premiere Pro 2021 official Chinese version installation tutorial

C language to realize mine sweeping

Pyqt interface production (login + jump page)

Zhonggan micro sprint technology innovation board: annual revenue of 240million, net loss of 17.82 million, proposed to raise 600million
随机推荐
Several sentences extracted from the book "leather bag"
牛客 BM83 字符串變形(大小寫轉換,字符串反轉,字符串替換)
Dllexport and dllimport
Qt—绘制其他东西
Luogu p5194 [usaco05dec]scales s solution
C language fcntl function
My QT learning path -- how qdatetimeedit is empty
[graphics] efficient target deformation animation based on OpenGL es 3.0
[opengl] bone animation blending effect
Piwigo 2.7.1 sqli learning
Zhonggan micro sprint technology innovation board: annual revenue of 240million, net loss of 17.82 million, proposed to raise 600million
复合类型(自定义类型)
Tailing rushes to the scientific and Technological Innovation Board: it plans to raise 1.3 billion, and Xiaomi Changjiang is the shareholder
Qt development - scrolling digital selector commonly used in embedded system
Fundamentals of PHP deserialization
[engine development] in depth GPU and rendering optimization (basic)
Zzuli: cumulative sum of 1050 factorials
Niuke bm83 string deformation (case conversion, string inversion, string replacement)
Pytorch深度学习和目标检测实战笔记
Yolov5进阶之九 目标追踪实例1