Qt四捨五入取模取餘操作

2021-06-13 17:33:53 字數 779 閱讀 2734

qt中有兩個函式進行四捨五入操作:qround與qround64。

qint64 qround64 ( 

qreal value )

將qreal型別的數值,四捨五入後返回乙個最近64位的整數,示例:

qreal valuea = 42949672960.3;

qreal valueb = 42949672960.7;

int roundedvaluea = qround(valuea);

// roundedvaluea = 42949672960

int roundedvalueb = qround(valueb);

// roundedvalueb = 42949672961

int qround ( qreal value )

四捨五入返回最近的整數值,示例:

qreal valuea = 2.3;

qreal valueb = 2.7;

int roundedvaluea = qround(valuea);

// roundedvaluea = 2

int roundedvalueb = qround(valueb);

// roundedvalueb = 3

上面四捨五入的進製基數是1,如果基數不等於1,就要自己寫round函式。

int getroung(int ivalue, int ibase)

返回網格內距離乙個給定點最近的網格點。

圍著點做乙個矩形,找出在矩形內的點。然後計算距離,找距離最近的點。

四捨五入 上取整 下取整

float tmpfloatdata2 3.7 nsstring tmpstr2 nsstring stringwithformat 0f tmpfloatdata2 nslog tmpstr2 tmpstr2 結果為4 float tmpfloatdata3 6.5 nsstring tmpstr...

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 ...

C 取整和四捨五入

向上取整 math.ceiling 1 1 math.ceiling 1.1 2 math.ceiling 1.5 2 向下取整 math.float 1 1 math.float 1.1 1 math.float 1.5 1 c 取整函式例項應用詳解 c 取整函式的相關使用是我們在實際開發應用中經...