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

Rounding to the closest 100

How do you round an integer to the closest 100? For example, 497 would round to 500, 98 would round to 100, and 1423 would round to 1400.
user3344370
3
votes
2 answers

Javascript Rouding in For statement

I have this line: for (var j = 0; j<1; j = (j + 0.1).toPrecision(1)) I'm trying to set up this statement so I get 0, 0.1, 0.2, 0.3 up to the number 1. At the moment I get 0, 0.1 and then nothing as if the result goes straight passed 1, Simply using…
YsoL8
  • 2,186
  • 5
  • 29
  • 47
3
votes
5 answers

PHP rounding error with simple multiplication

PHP seems to round incorrectly when using (int) to cast variables. Why? $multiplier = 100000000; $value = 0.01020637; echo (int)($value*$multiplier); Output: 1020636. (unexpected output) $multiplier = 100000000; $value = 0.01020637; echo…
bvpx
  • 1,227
  • 2
  • 16
  • 33
3
votes
6 answers

PHP Rounding Numbers

I cannot seem to figure out how to always round up in PHP. ceil() would be the obvious choice but I need the same functionality that round() provides with its second parameter "precision". Here is an example: // Desired result: 6250 echo…
Torez
  • 1,902
  • 7
  • 25
  • 39
3
votes
3 answers

Rounding nearest to (1, 1.5, 2, 2.5 etc..) javascript

To clarify, the problem is how to round a number like this. i.e. 1.512 should round to 1.5 and 2.123 should round to 2 and 2.323 should round to 2.5 (javascript)
GobyDot
  • 483
  • 3
  • 15
3
votes
2 answers

Whats the difference in these two ways to convert milliseconds to seconds?

First way: long mySeconds = milliseconds/ 1000; Second way: double mySeconds = milliseconds * 1e-3d; This calculation is finally used to determine index of an array, like this: int index = (int) ((someDoubleSeconds + mySeconds)/…
3
votes
1 answer

cancellation in numpy array operation including a scalar

I'm using NumPy version 1.7.1. Now I came across a strange cancellation I don't understand: >>> import numpy as np >>> a = np.array([ 883, 931, 874], dtype=np.float32) Mathematically a+0.1-a should be 0.1. Now let's calculate the value of this…
roettm
  • 33
  • 3
3
votes
2 answers

python 3.3.2 do I get the right understanding of the function "round"?

Sorry, but I really don't know what's the meaning of the defination of round in python 3.3.2 doc: round(number[, ndigits]) Return the floating point value number rounded to ndigits digits after the decimal point. If ndigits is omitted, it…
tcpiper
  • 2,456
  • 2
  • 28
  • 41
3
votes
1 answer

IEEE Rounding schemes

I am trying to learn the features of IEEE rounding from the following source On fast IEEE Rounding Can anyone one explain the equation for round up ? What does round up with fix up mean ? And what are floor and ceiling functions ? I tried IEEE 754…
chitranna
  • 1,579
  • 6
  • 25
  • 42
3
votes
6 answers

Math.Round, keep decimal place

For example. Math.Round(2.314, 2) //2.31 Math.Round(2.301, 2) //2.3 , but I want this as 2.30
Adrian
  • 836
  • 7
  • 20
  • 44
3
votes
3 answers

How can I make numbers more precise in Python?

I'm just learning the basics of Python at the moment and I thought that, as a learning exercise, I'd try writing something that would approximate the number "e". Anyway, it always gives the answer to 11 decimal places and I want it to give something…
M Smith
  • 430
  • 1
  • 7
  • 19
3
votes
1 answer

Why is the behavior of Double.toString not the same as MathContext.DECIMAL64 when constructing a BigDecimal in Java?

To me, it seems like Double should be following the same rules as the IEEE standard used in MathContext.DECIMAL64, however, in this case, I get different behavior: import java.math.BigDecimal; import java.math.MathContext; public class…
dave
  • 1,607
  • 3
  • 16
  • 20
3
votes
2 answers

Int() Function MS Access VBA

I'm implementing the AsymArith round method from http://support.microsoft.com/kb/196652 Now I run into a strange issue with the Int() function: it is supposed to only strip the fractional part, but it changes the integer portion as well. ? 131.415 *…
3
votes
6 answers

How to round a DateTime in MySQL?

I want to discretize the DateTime with the resolution of 5 minutes. I did it in C#, but how to convert the following code to MySQL? DateTime Floor(DateTime dateTime, TimeSpan resolution) { return new DateTime ( …
Jader Dias
  • 88,211
  • 155
  • 421
  • 625
3
votes
1 answer

Round to 0.5 or 1 in ruby

Where x is any integer, I have a value about x.1..x.4. I want to round it to x.5, and if it is above x.5, say x.7 or x.8, then it should round to (x+1).0. How is that possible? Is there a function in ruby?
Aravind
  • 1,391
  • 1
  • 16
  • 41