turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- How to do Bankers Rounding in JMP

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Nov 7, 2017 9:19 AM
(447 views)

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Nov 7, 2017 11:03 AM
(572 views)

Solution

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Nov 7, 2017 9:23 AM
(446 views)

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Nov 7, 2017 11:03 AM
(573 views)

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Nov 7, 2017 11:49 AM
(418 views)

Thanks!