当前位置:网站首页>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 )
边栏推荐
- Dllexport and dllimport
- Pytorch深度学习和目标检测实战笔记
- Rasterization: a practical implementation (2)
- 动态获取权限
- C language to implement a password manager (under update)
- My QT learning path -- how qdatetimeedit is empty
- Awvs batch operation script
- 亚马逊、速卖通、Lazada、Shopee、eBay、wish、沃尔玛、阿里国际、美客多等跨境电商平台,测评自养号该如何利用产品上新期抓住流量?
- adc128s022 ADC verilog设计实现
- 复合类型(自定义类型)
猜你喜欢
随机推荐
Zzuli:1040 sum of sequence 1
mmdetection 学习率与batch_size关系
Zzuli:1052 sum of sequence 4
Creation of data table of Doris' learning notes
C language STR function
牛客 BM83 字符串变形(大小写转换,字符串反转,字符串替换)
Yolov5进阶之八 高低版本格式转换问题
Bucket sorting in C language
Use of constraintlayout
Several sentences extracted from the book "leather bag"
NOI OPENJUDGE 1.6(09)
Find books ()
Zzuli:1053 sine function
Showmebug entered Tencent conference, opening the era of professional technical interview
[ue4] material and shader permutation
My QT learning path -- how qdatetimeedit is empty
7-3 rental (20 points)
Address book sorting
Tailing rushes to the scientific and Technological Innovation Board: it plans to raise 1.3 billion, and Xiaomi Changjiang is the shareholder
链表有环,快慢指针走3步可以吗








