如何做JMP中的銀行家四捨五入我最近被問及銀行家的四捨五入,但在JMP文檔中沒有找到任何內容。我寫了下面的快速功能(以及一個公式選項),但很奇怪,1)JMP有一個罐頭方法來做銀行家的捨入,2)其他/更好的方法可能對我有用。http://wiki.c2.com/?BankersRounding
bankerRound = Function( {inputValue},
{inputValue, fDiff, cDiff, modX, bankRound},
fDiff = inputValue - Floor( inputValue );
cDiff = Ceiling( inputValue ) - inputValue;
modX = Modulo( Round( inputValue, 0 ), 2 );
If(
cDiff == fDiff & modX == 0, bankRound = Ceiling( inputValue ),
cDiff == fDiff & modX != 0, bankRound = Floor( inputValue ),
bankRound = Round( inputValue, 0 )
);
Return( bankRound );
);
inputValue = Empty(); // put column name here
fDiff = inputValue - Floor( inputValue );
cDiff = Ceiling( inputValue ) - inputValue;
modX = Modulo( Round( inputValue, 0 ), 2 );
If(
cDiff == fDiff & modX == 0, bankRound = Ceiling( inputValue ),
cDiff == fDiff & modX != 0, bankRound = Floor( inputValue ),
bankRound = Round( inputValue, 0 )
);回复:JMP如何做銀行家四捨五入這看起來像一個更清潔的解決方案。太糟糕的JMP沒有這個作為罐裝圓角的東西。說實話,我不知道還有其他類型的四捨五入... 標準?四捨五入:)
謝謝!回复:JMP如何做銀行家四捨五入它不是內置的,但我認為這完成了同樣的事情:
bankerRound = Function( {inputValue},
if( mod(inputValue, 0.5) == 0 & ! mod(inputValue, 1) == 0,
round(inputValue / 2) * 2,
round(inputValue)
)
);
tests = { 0,0.499,0.5,0.501,1,1.499,1.5,1.501,2,2.499,
2.5,2.501,3,3.499,3.5,3.501,-0.499,-0.5,-0.501,
-1,-1.499,-1.5,-1.501,-2,-3};
for( i = 1, i <= N items( tests ), i++,
Write( char( tests[i] ) || " -> " ||
char( bankerRound( tests[i] ) ) || "\!N" );
);回复:JMP如何做銀行家四捨五入好吧,那看起來很糟糕...... 讓我們試試這兩個公式選項:
bankerRound = Function({inputValue},
{inputValue,fDiff,cDiff,modX,bankRound},
fDiff = inputValue - floor(inputValue);
cDiff = ceiling(inputValue) - inputValue;
modX = Modulo(round(inputValue,0),2);
if(cDiff == fDiff & modX == 0,
bankRound = Ceiling(inputValue)
,
cDiff == fDiff & modX != 0,
bankRound = Floor(inputValue);
,
bankRound = Round(inputValue,0);
);
Return(bankRound)
);
inputValue = Empty(); // place column name here
fDiff = inputValue - floor(inputValue);
cDiff = ceiling(inputValue) - inputValue;
modX = Modulo(round(inputValue,0),2);
if(cDiff == fDiff & modX == 0,
bankRound = Ceiling(inputValue)
,
cDiff == fDiff & modX != 0,
bankRound = Floor(inputValue);
,
bankRound = Round(inputValue,0);
);