中文四捨五入

2021-09-06 21:35:33 字數 877 閱讀 3973

以下是中文四捨五入的演算法,不是銀行的四捨五入。

public static class numbericextension

//小數點的位數沒有超過要保留的位數,則返回原資料+"保留小數字數 - 已有的小數字"個0

if ((sourcestring.length - sourcestring.indexof(".") - 1) <= toremainindex)

string beforeabandon_string = string.empty;

beforeabandon_string = sourcestring.substring(0, sourcestring.indexof(".") + toremainindex + 1);

//取得如3.1415926保小數點後4位(原始的,還沒開始取捨),中的3.1415

decimal beforeabandon_decial = convert.todecimal(beforeabandon_string);

//如果保留小數點後n位,則判斷n+1位是否大於等於5,大於,則進一,否則捨棄。

if (int.parse(sourcestring.substring(sourcestring.indexof(".") + toremainindex + 1, 1)) >= 5)

else

return result;

}///

/// 補 "0"方法.

///

/// 生成個數.

///

private static string createzeros(int zerocounts)

for (int i = 0; i < zerocounts; i++)

return result;}}

qt的四捨五入 Qt(C )四捨五入

qt現在是四捨六入五成雙,要想四捨五入得自己想辦法,實現如下 include include double c1 3.435 double c2 3.445 double c3 3.4351 double c4 3.4451 double c5 3.445 qdebug qdebug qdebug ...

mysql 金額 四捨五入 mysql四捨五入

雲資料庫 mysql 雲資料庫 rds for mysql 是穩定可靠 可彈性伸縮的雲資料庫服務。通過雲資料庫能夠讓您幾分鐘內完成資料庫部署。雲端完全託管,讓您專注於應用程式開發,無需為資料庫運維煩惱 低至 0.24 小時起,買1年83折 雲資料庫mysql 雲資料庫 rds for mysql 是...

c 四捨五入

在處理一些資料時,我們希望能用 四捨五入 法實現,但是c 採用的是 四捨六入五成雙 的方法,如下面的例子,就是用 四捨六入五成雙 得到的結果 double d1 math.round 1.25,1 1.2double d2 math.round 1.24,1 1.2double d3 math.ro...