Community Trekker

Joined:

Sep 27, 2016

## How to do Bankers Rounding in JMP

I was recently asked about banker's rounding and didn't find anything in the JMP documentation. I wrote the quick function below (as well as a formula option), but was curious if 1) JMP has a canned method for doing banker's rounding and 2) what other/better methods may be useful vs. mine. 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 )
);``````
1 ACCEPTED SOLUTION

Accepted Solutions

Community Trekker

Joined:

Sep 30, 2016

Solution

## Re: How to do Bankers Rounding in JMP

It is not built in but I think this accomplishes the same thing:

``````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" );
);``````
3 REPLIES

Community Trekker

Joined:

Sep 27, 2016

## Re: How to do Bankers Rounding in JMP

Ok, that looked horrible.... let's try this for the two formula options:

``````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);
);``````

Community Trekker

Joined:

Sep 30, 2016

Solution

## Re: How to do Bankers Rounding in JMP

It is not built in but I think this accomplishes the same thing:

``````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" );
);``````

Community Trekker

Joined:

Sep 27, 2016

## Re: How to do Bankers Rounding in JMP

That does look like a cleaner solution. Too bad JMP doesn't have this as a canned rounding thing. To be honest, I had no idea there were other kinds of rounding than ... standard? rounding :)

Thanks!