当前位置:网站首页>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 )
边栏推荐
- Tiantu investment sprint Hong Kong stocks: asset management scale of 24.9 billion, invested in xiaohongshu and Naixue
- Analysis of gene family characteristics - chromosome location analysis
- tonybot 人形机器人 查看端口并对应端口 0701
- cpu飙升排查方法
- Adobe Premiere Pro 15.4 has been released. It natively supports Apple M1 and adds the function of speech to text
- NOI OPENJUDGE 1.5(23)
- Zzuli:1046 product of odd numbers
- 论文分享:Generating Playful Palettes from Images
- 提高效率 Or 增加成本,开发人员应如何理解结对编程?
- Container of symfony
猜你喜欢

tonybot 人形机器人 红外遥控玩法 0630

Sword finger offer 28 Symmetric binary tree

QT - draw something else

tonybot 人形机器人 首次开机 0630

Amazon, express, lazada, shopee, eBay, wish, Wal Mart, Alibaba international, meikeduo and other cross-border e-commerce platforms evaluate how Ziyang account can seize traffic by using products in th

论文分享:Generating Playful Palettes from Images
![[graphics] efficient target deformation animation based on OpenGL es 3.0](/img/53/852ac569c930bc419846ac209c8d47.jpg)
[graphics] efficient target deformation animation based on OpenGL es 3.0

Pytorch深度学习和目标检测实战笔记
![洛谷P5018 [NOIP2018 普及组] 对称二叉树 题解](/img/89/da1a3a38e02671628f385de0f30369.png)
洛谷P5018 [NOIP2018 普及组] 对称二叉树 题解

Solve the problem that PR cannot be installed on win10 system. Pr2021 version -premiere Pro 2021 official Chinese version installation tutorial
随机推荐
1017 a divided by B (20 points)
pyQt界面制作(登录+跳转页面)
Analysis of gene family characteristics - chromosome location analysis
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
Plane vector addition
Tonybot Humanoïde Robot Infrared Remote play 0630
Bibit pharmaceutical rushed to the scientific innovation board: annual revenue of 970000, loss of 137million, proposed to raise 2billion
Zzuli:1052 sum of sequence 4
Déformation de la chaîne bm83 de niuke (conversion de cas, inversion de chaîne, remplacement de chaîne)
Showmebug entered Tencent conference, opening the era of professional technical interview
7-3 count the number of words in a line of text
表单文本框的使用(一) 选择文本
Niuke: crossing the river
Common commands for getting started with mongodb database
[opengl] geometry shader
NOI OPENJUDGE 1.3(06)
Zzuli: sum of 1051 square roots
ASTC texture compression (adaptive scalable texture compression)
Sword finger offer 28 Symmetric binary tree
How to query the baby category of tmall on Taobao