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

C# midpoint round down option for decimal

Im working with an external payment system which uses a round down at exact midpoint, but round up if its anything more than that. I want to replicate the same in my application to match the value. For example with two decimal point rounding,…
KeenUser
  • 5,305
  • 14
  • 41
  • 62
2
votes
0 answers

Why SQLite function Round() is returning different values on different Android devices?

I am creating a small Android app in which I am doing some math calculation, using both Java and SQLite. The issue is that the SQLite function round(...) return different value than Java Math.round(..) in some devices. To be more precise, my goal is…
YoucefB
  • 21
  • 2
2
votes
2 answers

How to round number in Python (many digits after comma)

How to print 2.7 having 2.6000000000000001. (Or any other numbers like this). import math print(math.ceil(2.6000000000000001)) // 3 print(round(2.6000000000000001, 2)) // 2.6 ???
2
votes
2 answers

Round a floating point number by a given precision

I need to get qty number by a specified precision like below: qty = 0.1284 precision = 0.01 output = 0.12 It seems easy, buy I could not get it done because I have a precision above variable.
tompal18
  • 1,164
  • 2
  • 21
  • 39
2
votes
1 answer

Serializing a double with JsonSerializer results in JSON with lower precision .net 5.0

While upgrading from dotnet core 2.2 to dotnet 5.0 we experienced failing tests that depend on consistent serilaization of objects to generate a hash. I have tracked this down to the way the double type is serialized when passed to the…
Dafydd Giddins
  • 2,276
  • 3
  • 24
  • 31
2
votes
3 answers

Round 37.1-28.75 float calculation correctly to 8.4 instead of 8.3

I have problem with floating point rounding. I want to calculate floating point numbers and round them to (given) N decimals. In this example I want to round to 1 decimal places. Calculation 37.1-28.75 will result into floating point 8.349998…
Tmas
  • 21
  • 6
2
votes
1 answer

Advanced rounding options with BigDecimal

I am writing a program that has to round very large and precise numbers (possibly many more significant digits than even double could handle), and am using BigDecimals. Is there a way to make BigDecimal round based on place and not significant…
donnyton
  • 5,874
  • 9
  • 42
  • 60
2
votes
3 answers

Python Round DOWN time to 5 minutes

I need to write a function that can ROUND DOWN time to 5 minutes. I mean if it's 17:01 it goes to 17:00, if it's 16:59 it goes to 16:55, if it's 16:51 it goes to 16:50, etc.
2
votes
3 answers

VBA User Defined Function to display 1/8th inch shows up blank

I'm very new to VBA. I wrote this UDF (my first proper bit of coding) and I'm screwing something up, but I don't know what. I know very little and am currently taking a course, but most answers seem interchangeable to my uneducated eyes. Also, if…
2
votes
2 answers

How to do "round half up" in tensorflow

I have some question when doing tf.round(x) x=[0.4, 1.5, 2.5, -1.5, -2.5, -0.4] If I want to get the ans=[0, 2, 3, -2, -3, 0] rounding half way away from zero How should I do? I've tried tf.keras.backend.round(), tf.math.round, tf.math.rint() I…
E.K.
  • 23
  • 2
2
votes
3 answers

Problem with nontypical rounding in python

I'm testing a system where is specific rounding - last number is always rounded up e.g. 123,459 should yield 123,46 99,9911 should yield 100,00 How can I implement it in python? EDIT The most important thing - those numbers are prices
user278618
  • 19,306
  • 42
  • 126
  • 196
2
votes
2 answers

How to round a list of decimals in Excel, so that the sum of the whole numbers equal a defined total?

Having difficulty developing an excel function that will round a list of decimals, so that the sum of the whole numbers equals the original or a defined total. Edit I guess one way to do it is writing a function that first searches for the largest…
whachem
  • 23
  • 6
2
votes
4 answers

How to round the minute of a timestamp to increments of 15?

I'm building an application to record when my cat has an asthma attack. I'm not interested in the exact time since glancing at the time in interval of 15 minutes is easier to review (e.g. rounding 9:38am should be recorded as 9:45am). I looked…
HPWD
  • 2,232
  • 4
  • 31
  • 61
2
votes
0 answers

Python(+pandas) round up if equally spaced

I have an application where the backend uses python with data in a pandas dataframe, and the frontend uses javascript. I am running into an issue where they round differently. Python rounds to the nearest even number if the distance between 2…
Dolf Andringa
  • 2,010
  • 1
  • 22
  • 36
2
votes
1 answer

f-string decimal formatting rounding

Other questions have indicated that Python f-strings round digits at a certain decimal place, as opposed to truncating them. I can show this with the following example: >>> number = 3.1415926 >>> print(f"The number rounded to two decimal places is…
jxmorris12
  • 1,262
  • 4
  • 15
  • 27