敲級簡單的東西 不過因為自己的電腦經常被自己瞎折騰所以儲存乙份到這裡洛 萬一以後用的上呢
用於字串數字的轉換 比如將10000 變成1.0萬 這樣用來顯示更加的人性化一些暫時是只寫了 萬和億的轉換,其實實質都一樣 可以自行自定義自己想要的方式。
public
class
numberutil
public
static string changeutil(string str)
if (i < 9 && i >= 5)
if (i >= 9)
return
str + util;
}// 小數點後一位的4舍5入
private
static string change(string str)
str = s + "." + change;
return
str;
}
效果:
int i =376435500;
system.out.printf( changeutil(i));
結果:3.8億
這個是用來在字串裡新增指定字串的方法 頭尾不新增 畢竟頭尾新增 直接用+ 就可以解決了
//str 原字元創 addstr需新增的 i 新增間隔
public
static string addstr(string str,string addstr,int i)
return sb.tostring();
}}
效果:
string str = abcdefgh;
string addstr = " "; //空格
system.out.printf(addstr(str,addstr,1));
結果:a b c d e f g h
數字和字串的轉換
一 字串轉為數字 1.parseint 對小數 進行取整 var num parseint 10 3 console.log num,typeof num number 將字串的小數轉為整數 型別是number var str 3.14 var num parseint str console.lo...
數字和字串之間的轉換
1.數字轉換成字串 1 std string to string intvalue 2 std string to string long value 3 std string to string long long value 4 std string to string unsigned val...
C C 數字和字串的轉換
今天,我在做題時候,遇到了字串和數字之間的轉換,現將轉換的方法總結如下。數字轉換成字串 include include using namespace std intmain 字串轉化成數字 include include using namespace std intmain 數字轉換成字串 in...