網站首頁 編程語言 正文
一、百分數
//按照四舍五入的國際標準
string p1 = (Math.Round(0.333367, 4)*100).ToString() + "%";//33.34%
double dbdata = Math.Round((double)1 / (double)3, 5) * 100;//33.333
string p2 = String.Format("{0:F}", dbdata) + "%";//默認為保留兩位
二、進制保留
帶小數點
//保證分母為double
double t = Math.Round(1.0 / 3, 5) * 100;//33.33
double tt = Math.Round(1.0 / 3.0, 5) * 100;//33.333
//m代表decimal.
decimal res = 100m / 1000;//0.1
不帶小數點
//保留為整數
double ttt = Math.Round(1.0 / 3.0, 0);//0
三、取余數
int a = 10 % 3;//取余數
byte數組操作
//1.字節轉換
float m = 5f;
var btValue = BitConverter.GetBytes(m).Reverse().ToArray();
//轉為原值字符串
string m1 = System.Text.Encoding.Default.GetString(btValue);
//2.byte 數組合并
byte[] data = new byte[10];
byte[] counts = new byte[3];
byte[] ndata = new byte[data.Length + counts.Length];
//將data復制到ndata
data.CopyTo(ndata, 0);//從ndata的下標為0的地方開始存放
counts.CopyTo(ndata, data.Length);
//3.string和byte[]轉換
string str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
//string轉byte[]:
byte[] byteArray1 = System.Text.Encoding.Default.GetBytes(str);
//byte[] 轉string:
string str1 = System.Text.Encoding.Default.GetString(byteArray1);
//string轉ASCII byte[]:
byte[] byteArray2 = System.Text.Encoding.ASCII.GetBytes(str);
//ASCII byte[] 轉string:
string str2 = System.Text.Encoding.ASCII.GetString(byteArray2);
//4.字符串拆分數組
string a = "A|B|C|D";
string[] a1 = a.Split('|');
//5.Int轉為16進制
int b = 58;
byte b1 = Convert.ToByte(b);
//6.byte數組截取
byte[] test = byteArray2.Skip(4).Take(3).ToArray();//從下標4開始截取長度3
//7.List轉為Byte[]
List<byte> frameBytes = new List<byte>();
frameBytes.Add(0x9E);
byte[] phoneNumByte = new byte[] { 0x01, 0x03, 0x05, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00 };//定義一個數組
for (int i = 0; i < phoneNumByte.Length; i++)
{
frameBytes.Add(phoneNumByte[i]);
}
frameBytes = frameBytes.Concat(byteArray2).ToList<byte>();//兩個list合并
//list轉byte[]
byte[] transByte = frameBytes.ToArray();
//byte[]轉list
List<byte> lb =transByte.ToList();
原文鏈接:https://www.cnblogs.com/wml-it/p/14953480.html
相關推薦
- 2022-09-25 TCP協議和UDP協議
- 2022-08-03 C++類與對象深入之引用與內聯函數與auto關鍵字及for循環詳解_C 語言
- 2022-12-04 Android嵌套線性布局玩法坑解決方法_Android
- 2022-08-14 python中matplotlib調整圖例位置的方法實例_python
- 2022-05-02 C++的輸入和輸出流詳解_C 語言
- 2022-11-02 python調用subprocess模塊實現命令行操作控制SVN的方法_python
- 2022-08-18 C#實現從位圖到布隆過濾器的方法_C#教程
- 2021-12-14 Qt?QMessageBox類使用教程_C 語言
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支