C 數值與字串之間相互轉換

2021-06-21 12:14:59 字數 634 閱讀 1680

c#中不僅僅存在數值型別的資料之間的轉換,字串和數值之間也是可以互相轉換的,只是方法不同而已。

1、數值型轉換為字元型

數值型資料轉換為字串用tostring()方法即可實現

int num1=10

string mynum=num1.tostring();

2、字串轉換為數值型

字串資料轉換為數值型使用pares()方法

字串轉換為整型用int.pares()

string str="13";

int number=int.pares(str);

字串轉換為雙精度浮點型  double.pares(string)

string str="14";

double number =double.pares(str);

字串轉換為單精度浮點型  float.parse(string)

string str="15";

float number=float.pares(str);

不是認識字串都可以轉換為數值型資料,只有能夠表示成數字的字串才可以進行轉換,例如名字「張三」,轉換成數字沒有可以符合的表示式,就不能實現轉換。

注意:pares() 括號中的引數只能是字串,不能為其他資料型別。

mysql時間與字串之間相互轉換

date format 日期,格式字串 select date format now y m d h i s str to date 字串,日誌格式 select str to date 2019 01 20 16 01 45 y m d h i s select unix timestamp no...

MySQL 時間與字串之間相互轉換

date format 日期,格式字串 select date format now y m d h i s str to date 字串,日誌格式 select str to date 2019 01 20 16 01 45 y m d h i s select unix timestamp no...

Qt數字與字串之間的相互轉換

把qstring轉換為 double型別 方法1.qstring str 123.45 double val str.todouble val 123.45 方法2.很適合科學計數法形式轉換 bool ok double d d qstring 1234.56e 02 todouble ok ok ...