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
5 answers

Rounding an array to values given in another array

Say I have an array: values = np.array([1.1,2.2,3.3,4.4,2.1,8.4]) I want to round these values to members of an arbitrary array, say: rounds = np.array([1.,3.5,5.1,6.7,9.2]) ideally returning an array of rounded numbers and an array of the…
Kieran Hunt
  • 1,738
  • 4
  • 17
  • 29
3
votes
4 answers

PHP: rounding a number into 16 decimal digits

Hi I'm trying to rounding a number into the 16 decimal digits but it only show and doesn't round up till 14 decimal digit. Here's my attempt:
Lutianna
  • 543
  • 1
  • 5
  • 15
3
votes
3 answers

rounding .5 down in java

How can you implement a rounding function which will round all numbers as usual except 0.5 or any odd multiple of it down to the nearest integer? For example: 2.899 is to be rounded up to 3.0 2.332 is to be rounded down to 2.0 2.5 is also to be…
Piyush Vishwakarma
  • 1,816
  • 3
  • 16
  • 24
3
votes
1 answer

Round half to even on decimal

R by default uses round half to even on the round() function. But it not seems to be always true when rounding to a defined number of decimal places: # R code round(1.225,2) #[1] 1.23 round(1.2225,3) #[1] 1.222 round(1.22225,4) #[1]…
art
  • 181
  • 1
  • 9
3
votes
1 answer

Is the rounding mode of large float literals well-specified?

Consider the following code: System.out.printf("%f%n", 123456796f); This prints 123456800 on my system, so the value was rounded up by 4. Is rounding up mandated in this situation, or could the compiler have decided to round down by 4 just as well,…
fredoverflow
  • 256,549
  • 94
  • 388
  • 662
3
votes
2 answers

how to do round half even in javascript unlimited digits after point?

I want to have 26.955 rounded to 26.96 I mean if I have numbers 0-4 I want to round them down and if they are 5-9 I want to round them up I considered parseFloat(number).toFixed(2) however it returns me 26.95, I need 26.96 I used Math.round but this…
Nickool
  • 3,662
  • 10
  • 42
  • 72
3
votes
2 answers

Proportional rounding error

I have a snippet of code that takes a large data set and turns it into proportional smaller data set let me explain: Lets say you have 20 blue marbles and 10 red marbles, if I wanted to represent this data with 3 marbles I would use 2 blue and 1 red…
3
votes
3 answers

HLSL tex2d sampler seemingly using inconsistent rounding; why?

I have code that needs to render regions of my object differently depending on their location. I am trying to use a colour map to define these regions. The problem is when I sample from my colour map, I get collisions. Ie, two regions with different…
RJFalconer
  • 10,890
  • 5
  • 51
  • 66
3
votes
1 answer

Rounding numbers and forcing R to display 0's

I am computing values, which are essentially decimal values and am also supposed to report them in a table. For the sake of neat presentation, how can I round all the values to 3 decimal places and even force R to add the 0's for the values with…
SavedByJESUS
  • 3,262
  • 4
  • 32
  • 47
3
votes
3 answers

PHP round the time to the nearest 15 seconds

This is not a duplicate question, but involves a little understanding about time. I need a solution to the following problem I have a number of specifically produced times (based on a date), that need to be rounded to the nearest 15 secs: 60 secs is…
Danny F
  • 392
  • 8
  • 21
3
votes
0 answers

Why does the difference of two rounded numbers not respected the rounded values in JavaScript?

I created a round function and it works fine in simple rounding. If I round two numbers A and B, and then I add them, the result is fine. But, if I "subtract" them, the result is weird. It is not rounded like it should. I show you the…
joaorodr84
  • 1,251
  • 2
  • 14
  • 33
3
votes
1 answer

CSS calc() rounding

This problem is similar to Chrome 37 calc rounding But the real problem was a bit more complicated, and the solution provided doesn't work for this case: #outerDiv, #leftDiv, #middleDiv, #rightDiv{ height: 100px; position:…
Anorionil
  • 505
  • 2
  • 7
  • 17
3
votes
1 answer

C# Formatting Currency

I am seeing an intriguing situation rounding Currency in C# (VS 2008 SP1). Below is an image of the test cases: alt text http://img697.imageshack.us/img697/8500/testcases.png I was expecting cases five, six, and seven (my bad on not numbering them…
blu
  • 12,905
  • 20
  • 70
  • 106
3
votes
2 answers

How to make round up to count up the even decimal value (example., if it is 2.25 it should round up to 2.3 not 2.2)

I am trying to format double value to one decimal point using below code but it produces two different rounding values. double d1= 4.55; double d2= 17.85; DecimalFormat oneDForm = new DecimalFormat("#.0"); …
pujari
  • 45
  • 5
3
votes
0 answers

Why delphi's RoundTo method behaves differently?

I have notice the RoundTo() function in both Delphi 7 and XE6 behave differently with some numbers and neither of them ad head to banker’s method as they said in the documentation. I pass the following number series to RoundTo(val, -4) in Delphi 7…
J Kok
  • 31
  • 1