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

SQL Server Automatic Rounding?

I am very confused by the following results: PRINT 3.1415926535897931 /180 Console result = 0.01745329251994329500 DECLARE @whatTheHell float(53) SET @whatTheHell = 3.1415926535897931/180 PRINT @whatTheHell Console result = 0.0174533 I don't…
Roubachof
  • 3,351
  • 3
  • 23
  • 34
2
votes
1 answer

TSQL round to half decimals

I want to round to the nearest half decimals (geo coordinates) to do some data visualization. In t-sql, is there a built in function to round to half decimals (if that is the term). Examples of desired result: 1.1 > 1.0 1.4 > 1.5 1.6 >…
Roger
  • 2,063
  • 4
  • 32
  • 65
2
votes
3 answers

How to Multiply Long by Double

Sorry for asking such a beginner question but I can't figure this out. I have a long integer that I'd like to divide by 1.28 then round it up or down to the nearest integer. long size = 24524343254; double ratio = 1.28; size = size * 1.28; //Error…
Andre Walker
  • 79
  • 1
  • 1
  • 11
2
votes
3 answers

How can I work around a round-off error that causes an infinite loop in Perl's Statistics::Descriptive?

I'm using the Statistics::Descriptive library in Perl to calculate frequency distributions and coming up against a floating point rounding error problem. I pass in two values, 0.205 and 0.205, (taken from other numbers and sprintf'd to those) to the…
NeilInglis
  • 3,431
  • 4
  • 30
  • 31
2
votes
1 answer

Working with percentage in c#

Ok, here's the thing. From DataTable i read number_of_project and number_of_hours_per_day (most of time 5 to 7 hours per day). For each project i insert percentage_value with dynamically created TextBoxes (Sum off all percentage_values is 100%).…
JanOlMajti
  • 1,387
  • 4
  • 22
  • 34
2
votes
4 answers

Java rounding with a bunch of nines at the end

It looks like BigDecimal.setScale truncates to the scale+1 decimal position and then rounds based on that decimal only. Is this normal or there is a clean way to apply the rounding mode to every single decimal? This outputs: 0.0697 (this is NOT the…
2
votes
5 answers

Dealing with hours with no minutes when rounding DateTime to the 30 minutes

I'm trying to emulate the way Google Calendar and Outlook handle time selection where all time entries are 30 minutes apart. I almost have every thing working with functional tests except for one thing. My problem is that I can't figure out how to…
Nosila
  • 540
  • 7
  • 20
2
votes
3 answers

Always rounding decimals up to specified precision

I'm looking for an elegant way to rounding up decimal numbers always up. Seems like round(0.0045001, 5, PHP_ROUND_HALF_UP); is not returning what I expected so I came up with following function; function roundUp($number, $precision) { $rounded =…
Revenant
  • 2,942
  • 7
  • 30
  • 52
2
votes
3 answers

Fractional Part of the number question

What is a good algorithm to determine the necessary fraction needed to add/sub to the number in order to round it to the nearest integer without using the inbuilt ceiling or floor funcitons? Edit: Looking for a mathematical number trick to figure…
unj2
  • 52,135
  • 87
  • 247
  • 375
2
votes
2 answers

Float round bug in ruby?

ruby-1.8.7 > 1.55.round(1) => 1.6 ruby-1.8.7 > 1.555.round(2) => 1.56 ruby-1.8.7 > 1.155.round(2) => 1.16 ruby-1.8.7 > 10.156.round(2) => 10.16 ruby-1.8.7 > 10.155.round(2) => 10.15 ruby-1.8.7 > 10.165.round(2) => 10.16 What gives? Am I…
tbk
  • 1,516
  • 3
  • 14
  • 21
2
votes
2 answers

php round up / ceil merge mysql AVG()

or Show Average i have this : $item = mysql_query("SELECT AVG(top) AS total FROM " . "$config_ccms_prefix" . "news where id='$id'"); while ($cms = mysql_fetch_assoc($item)) { $avg = ceil(($cms[total]),0.5); } //...... example…
Saimon Avazian
  • 281
  • 2
  • 6
  • 18
2
votes
0 answers

Truncate (not round) decimal in SQL

I'm doing astored procedure using a MySQL database. How could I round or truncate a FLOAT variable with diferent decimals? I've found this answer: Truncate (not round) decimal places in SQL Server Are any solution using just PL, not PL/SQL? Thanks…
dmunozpa
  • 131
  • 1
  • 7
2
votes
3 answers

Floating point multiplication in java

Possible Duplicate: How to round a number to n decimal places in Java When multiplying two numbers in java happens this: double a = 9.495 * 100; Expected result: a = 949.5; But the obtained result is: a = 949.4999999999999 When I try to round…
nikolavas
  • 63
  • 1
  • 2
  • 7
2
votes
4 answers

Rounding doubles for use in NSString

I have a situation where I have lots of different double values, for example 1.00, 0.25 and 2.50. I would like to round these doubles so that they become 1, 0.25 and 2.5; in other words I want to remove any trailing 0's. Is there a way to do…
user843337
2
votes
2 answers

Summing and rounding fractions multiplied by number to equal number?

In JavaScript, Given (x) number of fractions like this: 0.3 0.3 0.2 0.1 0.1 (That sum to 1) How can I make sure that when I multiply these by a number (n), say 1000, and round the results to integers, the sum of these integers will equal (n)?
dani
  • 4,880
  • 8
  • 55
  • 95