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

Limit the decimal place in JavaScript is not working in this math code?

Possible Duplicate: limit the decimal place in javascript is not working for 4.45678765e-6 This doesn't give me the answer I would get on a scientific calendar. var myNum = Math.floor (4.45678765 * 10000)/10000; document.write (x); Is it even…
David G
  • 94,763
  • 41
  • 167
  • 253
2
votes
2 answers

Inconsistent rounding after dividing an odd number by two

I have a problem with rounding decimal numbers that are exactly between two integers (I mean numbers like 0.5, 1.5, 2.5, etc.). When my program has to round such a number it does not always round up or always round down as I would expect, but rounds…
2
votes
2 answers

How to round a double to the closest odd integer in Java?

I want to round a double to the closest odd mathematical integer (long) in Java. Here is a test program: public class RoundToOdd { public static void main(String[] args) { System.out.println(roundToOdd(2.1)); // expected: 3 …
Daniel S.
  • 6,458
  • 4
  • 35
  • 78
2
votes
0 answers

ROUND() function doesn't work with OVER clause

The code below doesn't work when I replace SUM(Sales) with ROUND(SUM(Sales),2), works otherwise. Sales field type = Double. SELECT row_number() OVER (PARTITION BY Region) as Row_No, Name as Product, Category, Sales, SUM(Sales) OVER (PARTITION BY…
Sachin D
  • 73
  • 1
  • 2
  • 8
2
votes
2 answers

How to Force PySpark Rounding to Use Banker's Rounding

I need to round a column in PySpark using Banker's Rounding (where 0.5 is rounded to the nearest even number). So far, I've tried this: from pyspark.sql.functions round as _round df = df.withColumn(new_name, col(old_name) * col('ExchangeRate')) …
2
votes
1 answer

Accuracy of adding float number to itself vs multiplication by 2

Multiplying a float/double by 2 should be exact as it just increases exponent part. What about adding two floating numbers of same value? Will it be exact? (If it matters, hardware is standard x86-64).
user2052436
  • 4,321
  • 1
  • 25
  • 46
2
votes
1 answer

Google Sheets Less than or equal (<=) provide wrong result

Formula 0<=(1.36*100/1.36)-100 returns FALSE while expects TRUE. But 0<=(1.26*100/1.26)-100 returns correct result TRUE. Why?
2
votes
1 answer

Rounding Floating point numbers in Perl ..large inefficient but working solution

I had to round numbers that are a result of MySQL Querys. I didn't find a good solution for rounding in the correct way (truncating is not the correct way in my opinion). I wrote this code that rounds float numbers and also formatted the numbers in…
2
votes
1 answer

Is there a function in R to connect tapply with round?

Probably the solution is simple, but I can't find it right now. I like to use tapply in descriptive-statistical analyses. For example: tapply(dataframe1$Means, dataframe2$gender, function(x) { c( "mean" = mean(x, na.rm = TRUE), "sd" =…
formatc
  • 35
  • 5
2
votes
4 answers

Round number down to the next 1000 in python

can somebody tell me how i can round down to the nearest thousand. So far I tried it with math.round(), the truncate function but i couldn't find my math skills to work out for me. As a example for some people I want that 4520 ends up in beeing…
2
votes
2 answers

Rounding floats in Python

I have a large list of floats between 0 and 1 as seen below: l1 = [0,0.2,0.9,0.75,0.3,1,0.43,0.65] what i would like is to round these floats to the numbers: l2 = [0,0.25,0.5,0.75,1] Result here would be: r = [0,0.25,1,0.75,0.5,1,0.5,0.75] What i…
kokorilos
  • 21
  • 1
2
votes
1 answer

How do I calculate percentage as integer in PostgreSQL

I have a CTE (cte_person_count) with the following result: | name | count | ------------------ | Mike | 9 | | Jane | 4 | | Frank | 3 | | Brian | 2 | | Ann | 2 | | Other | 15 | From this cte I want to calculate the…
TheStranger
  • 1,387
  • 1
  • 13
  • 35
2
votes
1 answer

How to round integer number using precision in flutter

I am trying to make the Y axis intervals of linechart dynamic in flutter. Here the MaxVal will get the maximum value of the Y axis. int interval = (maxVal/6).toInt(); int length = interval.toString().length.toInt(); So here I have divided the…
Midlaj
  • 215
  • 2
  • 9
2
votes
1 answer

MYR Currency Rounding

Looking for help in rounding the money to the nearest 0.05 in js language. Input & Expected Output: 1.10 => 1.10 1.11 => 1.10 (round down) 1.12 => 1.10 (round down) 1.13 => 1.15 (round up) 1.14 => 1.15 (round up) 1.15 => 1.15 1.16 => 1.15 (round…
Thomas
  • 218
  • 2
  • 4
  • 9
2
votes
1 answer

How to emulate Excel's automatic rounding?

When Excel reports the results of a floating point calculation, it appears to round it to the correct precision based on the significant digits in the input numbers. But if I include the result in a text string, it includes the full precision,…
NewSites
  • 1,402
  • 2
  • 11
  • 26