bankers-rounding

Rounding Standards - Financial Calculations

家住魔仙堡 提交于 2019-12-31 08:11:52
问题 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 is then used for further calculations, should be use the "rounded" figure or the "raw" figure? Does anyone have any advice? Please note that I am aware of different rounding methods, i.e. Bankers Rounding etc. 回答1: The first and most important rule:

C# banker's rounding error

风流意气都作罢 提交于 2019-12-21 09:27:59
问题 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 about banker's rounding? Thanks.. 回答1: As Matthew said, 18.565 can't be accurately represented. The actual value used is 18.565000000000001278976924368180334568023681640625 (found using DoubleConverter), which is clearly beyond half-way. Now I've a

Rounding Standards - Financial Calculations

十年热恋 提交于 2019-12-02 15:50:34
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 is then used for further calculations, should be use the "rounded" figure or the "raw" figure? Does anyone have any advice? Please note that I am aware of different rounding methods, i.e. Bankers Rounding etc. The first and most important rule: use a decimal data type , never ever binary floating-point types. When exactly rounding should be performed

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

拥有回忆 提交于 2019-11-29 07:32:13
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 and by default has it been set to round down? I'm assuming depending on the machine and Powershell environment, I may get 3 at some points and 2 at others. [Math]::Floor($a) --> 2 [Math]::Ceiling($a)--> 3 [Math]::Round($a) --> 2 Floor will give you the preceding whole number and Ceiling will be providing the succeeding whole number. But if you want to

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

筅森魡賤 提交于 2019-11-28 01:11:59
问题 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 and by default has it been set to round down? I'm assuming depending on the machine and Powershell environment, I may get 3 at some points and 2 at others. 回答1: [Math]::Floor($a) --> 2 [Math]::Ceiling($a)--> 3 [Math]::Round($a) --> 2 Floor will give you

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

半城伤御伤魂 提交于 2019-11-26 01:26:56
问题 I want to do this using the Math.Round function 回答1: Here's some examples: decimal a = 1.994444M; Math.Round(a, 2); //returns 1.99 decimal b = 1.995555M; Math.Round(b, 2); //returns 2.00 You might also want to look at bankers rounding / round-to-even with the following overload: Math.Round(a, 2, MidpointRounding.ToEven); There's more information on it here. 回答2: Try this: twoDec = Math.Round(val, 2) 回答3: Personally I never round anything. Keep it as resolute as possible, since rounding is a