Home:ALL Converter>How to use Banker's Rounding Mode in Postgresql?

How to use Banker's Rounding Mode in Postgresql?

Ask Time:2018-08-03T05:08:24         Author:dfritch

Json Formatter

I have tried to search, but I can't seem to find an implementation of Banker's Rounding Mode in Postgresql. I found this thread in which there was an effort to create an implementation in T-SQL https://www.sqlservercentral.com/Forums/Topic246556-8-1.aspx.

For example, Andrew Vasylevskyy nicely gives some examples Examples of banker's rounding (results of Math.Round in .NET):

Math.Round(3.454,2) -> 3.45
Math.Round(3.455,2) -> 3.46
Math.Round(3.445,2) -> 3.44
Math.Round(3.456,2) -> 3.46 

Based on this thread PostgreSQL round(v numeric, s int) it appears that there is not a way to configure the default round() function to use a specific mode and that it does not use Banker's Rounding Mode. I do see there is a round_half_even or a round_half_odd but it is my understanding it is not the same as Banker's rounding.

Has anyone created a function that does this or is there an extension out there that can be added to do this?

Author:dfritch,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/51662190/how-to-use-bankers-rounding-mode-in-postgresql
yy