Questions tagged [rounding]

Rounding a numerical value means replacing it by another value that is approximately equal but has a shorter, simpler, or more explicit representation.

Rounding a numerical value means replacing it by another value that is approximately equal but has a shorter, simpler, or more explicit representation; for example, replacing £23.4476 with £23.45, or the fraction 312/937 with 1/3, or the expression √2 with 1.414.

5484 questions
3
votes
4 answers

BigDecimal format with DecimalFormat

I'm trying to get predictable behavior with rounding BigDecimal numbers to 15th digit. As a result I'm getting some either round up or round down. import java.math.BigDecimal; import java.math.MathContext; import java.math.RoundingMode; import…
dgene00
  • 31
  • 1
  • 2
3
votes
3 answers

Round up midpoint rounding option in c#

Although I've seen several questions about rounding, I haven't found an answer to this. Is there any way in C# / .Net to do midpoint rounding up? That is to say, if a decimal is halfway between 2 integers, I want to always round UP. As far as I…
GendoIkari
  • 11,734
  • 6
  • 62
  • 104
3
votes
4 answers

Decimal rounding strategies in enterprise applications

Well, I am wondering about a thing with rounding decimals, and storing them in DB. Problem is like this: Let's say we have a customer and a invoice. The invoice has total price of $100.495 (due to some discount percentage which is not integer…
Denis Biondic
  • 7,943
  • 5
  • 48
  • 79
3
votes
3 answers

Round up numbers so it is divisible by m (in R)

What is the easiest way to round up x so that it is divisible by m ? For example, if x = 114, m =4, then the round up should be 116 or if x = 119, m=5, then the round up should be 120
Adrien
  • 151
  • 1
  • 8
3
votes
3 answers

switch to DST: round_date() returns NAs

In 2013, the switch from Central European Time (CET) to Central European Summer Time (CEST) took place on Sunday 2013-03-31. Clocks are advanced by one hour from 2am to 3pm, so basically there is no 2am. start <- strptime("2013-03-31 01:00:00",…
Tobias
  • 422
  • 2
  • 6
3
votes
3 answers

Trailing zeros after sequential rounding with round() followed by signif()

I am trying to apply a sequential rounding function on any real number so that the following condition is met: "Numbers should be reported with no more than two decimal digits and no more than two significant figures". For example: 0.0236 should be…
3
votes
3 answers

Rounding a number with different resolutions

With C# I need an elegant way to round a number with a resolution of 1/8 to a resolution of 1/2 with the following rules: Round(0) = 0 Round(0.125) = 0 Round(0.25) = 0 Round(0.375) = 0.5 Round(0.5) = 0.5 Round(0.625) = 0.5 Round(0.75) =…
CodeMonkey
  • 11,196
  • 30
  • 112
  • 203
3
votes
1 answer

How does java round an integer when stored in a floating point

Its a classic problem: your legacy code uses a floating point when it should really be using n integer. But, its to expensive to change every instance of that variable (or several) in the code. So, you need to write your own rounding function that…
Erik Helleren
  • 1,481
  • 1
  • 10
  • 7
3
votes
8 answers

If I divide 3 by 2 I want the answer to be 2 (ie 1.5 rounded to 2)

How to get he upper limit of a number in C? If I divide 3 by 2 I want the answer to be 2 (ie 1.5 rounded to 2).
Eternal Learner
  • 3,800
  • 13
  • 48
  • 78
3
votes
2 answers

What is the ruby expression "%.1f" and how does this round a decimal?

I want to round a float with many decimal places, such as 2.638232371 down to one decimal place, such as 2.6. I found this will do so: "%.2f" % 1.93213 #=> 1.93 But what is "%.2f"? and is the result a string? I'd just like to understand how this…
GroundBeesAhh
  • 133
  • 1
  • 4
  • 11
3
votes
4 answers

Python - round a float to 2 digits

I would need to have a float variable rounded to 2 significant digits and store the result into a new variable (or the same of before, it doesn't matter) but this is what happens: >>> a 981.32000000000005 >>> b= round(a,2) >>>…
user3484521
  • 39
  • 1
  • 2
3
votes
6 answers

Rounding up a time to the nearest hour

ok basically I have a program that is re-writing text files and formatting them through various conditions, one of the conditions is that the date and time values in my original text file needs to be removed from its current location and moved into…
JoshF91
  • 99
  • 1
  • 3
  • 11
3
votes
1 answer

How can I keep trailing zeros in a list or np.array?

I'm performing a little bit of statistics using python, I have this dataset: test=[0.200,0.220,0.220,0.120,0.330,0.330] Python automatically convert it in [0.2, 0.22, 0.22, 0.12, 0.33, 0.33] but in fact the zeros are significant figures in my…
G M
  • 20,759
  • 10
  • 81
  • 84
3
votes
2 answers

Round up double to long in Java

Is there a method in java which round up double to Long in java? eg. double d=2394867326.23; I need to round this up to 2394867327. The result is not an integer, so I think cannot use Math.ceil. Do we have a method in java which return the Long…
MukeshKoshyM
  • 514
  • 1
  • 8
  • 16
3
votes
3 answers

How to round a byte to 0 or 255 using shift operators

For recolering the pixels in a bitmap image in my C# project I want to round my RGB values either up to a value of 255 or down to 0; Each value is a byte. Right now I am doing the following: (byte)(Pixels[i] < 128 ? 0 : 255); I am sure this could…
Michael Frey
  • 908
  • 2
  • 14
  • 35