C Double保留小數點後面位數

2022-05-10 17:56:46 字數 932 閱讀 1539

double salary1 = 10000.0;

double salary2 = 10000.12345;

double salary3 = 10000.1289;

int salary4 = 10000;

string salary5 = "10000";

string salary6 = "10000.12345";

string salary7 = "10000.1289"

convert.todouble(salary1).tostring("0.00");//保留小數點後兩位,結果為10000.00

convert.todouble(salary2).tostring("0.00");//保留小數點後兩位,結果為10000.12

convert.todouble(salary3).tostring("0.00");//保留小數點後兩位,結果為10000.13

convert.todouble(salary4).tostring("0.00");//保留小數點後兩位,結果為10000.00

convert.todouble(salary5).tostring("0.00");//保留小數點後兩位,結果為10000.00

convert.todouble(salary6).tostring("0.00");//保留小數點後兩位,結果為10000.12

convert.todouble(salary7).tostring("0.00");//保留小數點後兩位,結果為10000.13  

int a = 90;

int b = 110;

string c = (convert.todouble(a) * 100/convert.todouble(b)).tostring("f1");

console.writeline(c);

console.readline();

C Double保留小數點後面位數

double test1 1000.0 double test2 1000.12345 double test3 1000.1289 int test4 1000 string test5 1000 string test6 1000.12345 string test7 1000.1289 con...

C 小數點保留倆位小數

今天在做一些資料運算的時候,發現有一些資料是小數點後面無數個,看著我都蒙。我想你們也遇到過吧,不多說,直接上 1 math.round 0.333333,2 四捨五入的國際標準2 double dbdata 0.335333 string str1 string.format dbdata 預設為保...

C Double toString保留小數點方法

有時候double型資料需要tostring 但又想保留小數,當值為整數,比如3.00時tostring後會變為 3 具體說明見下 1 stringstr0 i.tostring f 2 stringstr1 i.tostring f1 3 stringstr2 i.tostring f2 4 st...