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

Rounding up and rounding down bill amount

I'm facing a problem to get the digit of a number after decimal point. I need the digit to do if else statement. Here is an example: 31.30 = 31.30 31.31 = 31.30 31.32 = 31.30 31.33 = 31.35 31.34 = 31.35 31.35 = 31.35 31.36 = 31.35 31.37 =…
Lee
  • 23
  • 4
2
votes
3 answers

Doubles, Ints, Math.Round in C#

I have to convert a double value x into two integers as specified by the following... "x field consists of two signed 32 bit integers: x_i which represents the integral part and x_f which represents the fractional part multiplied by 10^8. e.g.: x of…
Michael Covelli
  • 2,113
  • 4
  • 27
  • 41
2
votes
2 answers

format a number as I want

I have the number: a = 3.860575156847749e+003; and I would show it in a normal manner. So I write b = sprintf('%0.1f' a);. If I print b I will get: 3860.6. This is perfect. Matter of fact, while a is a double type, b has been converted in char.…
BAD_SEED
  • 4,840
  • 11
  • 53
  • 110
2
votes
2 answers

Math.Round() seems to be not consistent

Possible Duplicate: .Net Round Bug In C#: Math.Round(2.5) result is 2 (instead of 3)! Are you kidding me? Code: var d1 = Math.Round(187.5); // 188 var d2 = Math.Round(62.5); // 62 Why is it so?
Rookian
  • 19,841
  • 28
  • 110
  • 180
2
votes
4 answers

ruby to_f bug or multiplication operator bug?

Hi I just ran into an issue where ruby's to_f function is giving me inconsistent results. ruby-1.9.2-head :026 > 8.45.to_f * 100 => 844.9999999999999 ruby-1.9.2-head :027 > 4.45.to_f * 100 => 445.0 ruby-1.9.2-head :028 > 4.35.to_f * 100 =>…
NoTiTo
  • 21
  • 2
2
votes
6 answers

Round towards a given number

Can someone please provide code (any language will do, but I write the .Net languages and VB6) for an algorithm that rounds numbers ending with 5 towards a given number? RoundTo(double value, double toWards, int…
Dabblernl
  • 15,831
  • 18
  • 96
  • 148
2
votes
3 answers

round function in c #

public static decimal Round( decimal d, int decimals ) The decimals parameter specifies the number of fractional digits in the return value and ranges from 0 to 28. If decimals is zero, an integer is returned. If the value of the first digit…
coder25
  • 2,363
  • 12
  • 57
  • 104
2
votes
2 answers

How do I round the numbers in a df column correctly in Python?

The following is my df: https://www.dropbox.com/s/nbez3esbo8fedmf/aapl.csv?dl=0 date ticker open high low close adjClose 2019-07-08 AAPL 50.2025 50.35 49.6025 50.005 48.516 2019-07-09 AAPL 49.8 50.3775 49.7025 50.31…
saga
  • 736
  • 2
  • 8
  • 20
2
votes
2 answers

Formatting decimal with inline conditional statement

I'm wondering why there is an inconsistency with the code below. I would expect the same output, but when using the inline conditional statement, it appends a .0 to the string. Do I have some error in my code? double d = 10.1; String…
bradvido
  • 2,743
  • 7
  • 32
  • 49
2
votes
4 answers

Display a percentage in a label

I am working on a C# windows application. I have a label on my form that I want to display a calculation. Here is my code: this.lblPercent.Text = (Convert.ToString(totalPercent)); I have the variable totalPercent defined as a double, how do I…
Susan
2
votes
1 answer

Can the x87 perform exact division on UNsigned QUADword integers?

The 8086/8087/8088 MACRO ASSEMBLY LANGUAGE REFERENCE MANUAL (c) 1980 Intel Corporation mentions (Emphasis mine): ... the 8087 provides a very good approximation of the real number system. It is important to remember, however, that it is not an…
Sep Roland
  • 33,889
  • 7
  • 43
  • 76
2
votes
0 answers

Area and volume won't round off correctly and my first tab (last line) won't display, what am I doing wrong? (1st week of python)

#import square root function from math from math import sqrt print("Cuboid Calculator") print() #Input #Gather width, length and height with user input w = float(input("Enter the width (cm): ")) l = float(input("Enter the length (cm): ")) h =…
2
votes
2 answers

Pandas/Datetime rounding error (Rounding to 10 seconds)

I have a problem using the round() funktion on a pandas.Series / DataFrame filled with Timestamps. Code example to round to the nearest 10-second mark: import pandas as pd date = pd.DataFrame([pd.to_datetime('2022-03-02 06:46:05'),…
JaboSammy
  • 35
  • 4
2
votes
2 answers

Rounding numbers to the nearest decimal places in R

Consider the following data set: df <- data.frame(id=1:10, v1=c(2.35456185,1.44501001,2.98712312,0.12345123,0.96781234, 1.23934551,5.00212233,4.34120000,1.23443213,0.00112233), …
iGada
  • 599
  • 3
  • 9
2
votes
3 answers

How to round down a datetime to the nearest 5 Minutes?

I need a Python3 function that rounds down a datetime.datetime object to the nearest 5 minutes. Yes, this has been discussed in previous SO posts here and here and even here, but I'm having no luck implementing their solutions. NOTE: I can not use…
Pete
  • 1,511
  • 2
  • 26
  • 49