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

Truncate results from SQL to integer value

I have different data values (types), like 10.00 or 2.00. How can I get only its integer value, so I want to get 10 instead of 10.00 and 2 instead of 2.00?
Darjeeling
  • 959
  • 5
  • 19
  • 40
3
votes
2 answers

Why does round(2.49999999999999992) returns 3

I'm working on the math program and I have a quite big problem with round. So after my program did some math, it rounds the result. Everything works fine but if the result == 2.49999999999999992 , round function return 3.0 instead of 2.0. How can I…
Michael
  • 15,386
  • 36
  • 94
  • 143
3
votes
5 answers

Format a double to two digits after the comma without rounding up or down

I have been searching forever and I simply cannot find the answer, none of them will work properly. I want to turn a double like 0.33333333333 into 0,33 or 0.6666666666 into 0,66 Number like 0.9999999999 should become 1 though. I tried various…
FrozenHaxor
  • 59
  • 1
  • 2
  • 8
3
votes
1 answer

python float formatting weirdness?

I'm trying to debug two different python scripts that execute very similar code. These scripts set a, which is a simple float. For script 1: ipdb> print sys.version 2.7 (r27:82500, Jul 15 2010, 13:04:38) [GCC 4.1.2 20071124 (Red Hat…
asf107
  • 1,118
  • 7
  • 22
3
votes
1 answer

Implement Python 3's round function in Python 2.7

I am using some old codes written in Python 3 in my Google-App-Engine project which is using Python 2.7. The different round() algorithms in Python 3 and Python 2 gives me a headache. Is there any convenient way to implement a Python 3's round()…
3
votes
2 answers

PHP round to precision 2

My payment system takes 0.5% from each transaction. I have 0.9$ on my account, very small amount. And when I try to withdraw 0.9$ through API it gives an error, it takes 0.0045$ as fee and rounds to 0.91$. So I can only withdraw 0.89$ and pay…
user1482261
  • 191
  • 3
  • 15
3
votes
2 answers

How do I correctly round a float Android?

Why do these tests behave differently? public void testRoundFloat() { final NumberFormat format = NumberFormat.getNumberInstance(); format.setMaximumFractionDigits(2); format.setMinimumFractionDigits(2); …
Markus K
  • 1,585
  • 2
  • 17
  • 25
3
votes
1 answer

controlling if the number is being rounded up or down in python

So I know how to round a number in python. It's fairly straightforward. But I'm wondering is there a way to round a random floating point up to the next integer. Or round it straight down. So if there was 8.7 to have the choice to bring it down to…
Greg Peckory
  • 7,700
  • 21
  • 67
  • 114
3
votes
3 answers

PHP decimal position of math result

If variable A = 0.07 when echoed and variable B = 2100.00 when echoed if we: $c = $a * $b; when the end result is a whole # ( i.e. $c = 147) is there any way to force the result to keep 2 decimal places and hold the trailing zero's so that ( $c =…
DMSJax
  • 1,709
  • 4
  • 22
  • 35
3
votes
4 answers

How to see if a number ends in .0

I am trying to run a test if the number ends in .0 I am running a program with numbers orders of magnitude apart so I can't estimate to a certain amount of digits. using % doesn't work either because then certain numbers are excluded. All the…
Felis Vulpes
  • 33
  • 2
  • 7
3
votes
1 answer

Round a double number when printing to cout

I want to print only one digit after the decimal dot. So I write: double number1 = -0.049453; double number2 = -0.05000; cout.setf(ios::fixed,ios::floatfield); cout.precision(1); cout << number1 << endl; cout << number2 << endl; My output…
Alon Shmiel
  • 6,753
  • 23
  • 90
  • 138
3
votes
2 answers

How to round up a decimal?

How can I use round() to round a number to the superior number as soon as there is a decimal? For example: 1.00001 = 2 1.1 = 2 1.4785834975 = 2 1.00 = 1 1.99 = 2 3.01 = 4
456543646346
  • 973
  • 4
  • 15
  • 22
3
votes
2 answers

Linq data type comparison with Double

In my Linq query I have a where statement that looks like this && vio.Bows.Any(nw => nw.XCoordinate.Equals(currVio.XCoordinate))) values are nw.XCoordinate = 4056.48751252685 currVio.XCoordinate = 4056.488 Thus the statement of Equals is not…
user2300652
3
votes
1 answer

Rounding to specified absolute decimal precision in C90/99

I am working on software that, among other things, converts measured numbers between text and internal (double) representation. A necessary part of the process is to produce text representations with the correct decimal precision based on the…
John Bollinger
  • 160,171
  • 8
  • 81
  • 157
3
votes
1 answer

What is the most efficient way to format strings with rounding and thousand separator in C?

So I have an inner loop situation with a buffer of floating point and integer values that are to be copied over to a another buffer in string format. What are my alternatives to round and insert a thousand separator when formatting strings? Whatever…
c00kiemonster
  • 22,241
  • 34
  • 95
  • 133