Questions tagged [bankers-rounding]

25 questions
428
votes
15 answers

How do you round a number to two decimal places in C#?

I want to do this using the Math.Round function
Laila
33
votes
5 answers

Rounding Standards - Financial Calculations

I am curious about the existence of any "rounding" standards" when it comes to the calculation of financial data. My initial thoughts are to perform rounding only when the data is being presented to the user (presentation layer). If "rounded" data…
Guamez
  • 335
  • 1
  • 4
  • 6
10
votes
6 answers

IEEE-754 compliant round-half-to-even

The C standard library provides the round, lround, and llround family of functions in C99. However, these functions are not IEEE-754 compliant, because they do not implement the "banker's rounding" of half-to-even as mandated by IEEE. Half-to-even…
68ejxfcj5669
  • 485
  • 3
  • 11
8
votes
4 answers

C# banker's rounding error

double a = 18.565 return Math.Round(a,2) ..returns 18.57. For every other number I tried banker's rounding worked as expected, for example Math.Round(2.565,2) returned 2.56. Any clue why and when that happens? Is it error or am I missing something…
Damir
  • 337
  • 4
  • 15
6
votes
4 answers

Is there a way to do 'correct' arithmetical rounding in .NET? / C#

I'm trying to round a number to it's first decimal place and, considering the different MidpointRounding options, that seems to work well. A problem arises though when that number has sunsequent decimal places that would arithmetically affect the…
sunside
  • 7,545
  • 8
  • 47
  • 71
5
votes
2 answers

Powershell: convert a fraction to an integer - surprising rounding behavior

I have a interesting question on ints with decimals. Assuming I do the following: [int] $a = 5/2 $a I've tried it 10 times to be sure, and powershell always returns 2 Is there a way to force Powershell to round up or down in such circumstances…
Aiden
  • 151
  • 2
  • 12
5
votes
5 answers

.NET currency formatter: can I specify the use of banker's rounding?

Does anyone know how I can get a format string to use bankers rounding? I have been using "{0:c}" but that doesn't round the same way that bankers rounding does. The Math.Round() method does bankers rounding. I just need to be able to duplicate how…
user21767
  • 95
  • 5
3
votes
2 answers

Math.Round(1.225,2) gives 1.23, shouldn't it give 1.22

AFAIK .NET's default round option is to even, so Math.Round(1.225,2) should give 1.22 but it gives 1.23. Math.Round(2.225,2) = 2.22 Math.Round(100.225,2) = 100.22 all the values I tried rounds to nearest even but only 1.225 and -1.225 rounds to…
3
votes
1 answer

ARM NEON convert f32 to s32 with round toward even

Is there any functions that controls rounding mode of vcvt_s32_f32 intrinsic? I want to use round toward even instead of round toward negative infinity. Thanks.
sandye51
  • 91
  • 9
3
votes
4 answers

Rounding Issue using Math.Round

Module Module1 Public Sub Main() Dim values() As Double = {43.523, 12.65, 43.565} For Each value As Double In values Console.WriteLine("{0} --> {1}", value, Math.Round(value, 2)) Next Console.ReadLine() End Sub End…
John
  • 777
  • 1
  • 10
  • 23
2
votes
1 answer

How to use Banker's Rounding Mode in Postgresql?

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…
dfritch
  • 199
  • 1
  • 9
2
votes
1 answer

Should IEEE (binary) rounding rules be used on exact decimal inputs?

Say I am rouding the number 1.20515 to 4 decimal places in IEEE-compliant languages (C, Java, etc.) using the default round-to-half-even rule, the result will be "1.2051" which is not even. I think this is due to the fact that 1.20515 is slightly…
billc.cn
  • 6,543
  • 2
  • 33
  • 69
2
votes
2 answers

Java rounding issue with BigDecimal and calculations

I have a data set which consists of BigDecimal numbers. I want to present this in a report. I have managed to generate a report with the following format. This is somewhat similar to a trial balance in accounting. But it is not! The data in the…
LalakaJ
  • 531
  • 6
  • 15
1
vote
3 answers

round function in c #

public static decimal Round( decimal d, int decimals ) The decimals parameter specifies the number of fractional digits in the return value and ranges from 0 to 28. If decimals is zero, an integer is returned. If the value of the first digit…
coder25
  • 2,069
  • 9
  • 46
  • 86
1
vote
1 answer

Why does DecimalFormat round inconsistently?

import java.text.*; public class TryStuffOut { public static void main(String[] args) { double n=12323233.445; DecimalFormat x = new DecimalFormat("#.##"); System.out.println(x.format(n)); } } why does this round the…
Tony
  • 210
  • 9
1
2