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
1 answer

numpy.linspace Floating Point Inaccuracy

Can someone explain, what's going on here? And what is the best practice of how to properly / robustly check if something is contained within an array? Python 3.9.6 (default, Jun 30 2021, 10:22:16) [GCC 11.1.0] on linux Type "help", "copyright",…
Suuuehgi
  • 4,547
  • 3
  • 27
  • 32
2
votes
4 answers

Is there a specific function that allows me to round up to a specific decimal number in PHP

I have a number that needs to be rounded up to a specific decimal, is there any function in PHP to do that? I need every number (which reflects an amount of money) to have a specific decimal number. For example: The decimal needs to be 25, so if I…
Rosamunda
  • 14,620
  • 10
  • 40
  • 70
2
votes
2 answers

why does the number 51444.325061 doesnot round off to 51444.325 upto 3 decimal places? I want to round off this number in c programming

#include #include int main() { float n; scanf("%f", &n); printf("%.3f", n); } input: 51444.325061 my output: 51444.324 expected output: 51444.325 why does I dont get the proper answer?
2
votes
3 answers

R shows too few digits

I wanted to calculate that term: (21000*(1.022^7-1))/(1.022-1) R tells me, it's 157065.7. This was my answer to a task that I had to solve. It was stated that this answer is not correct, the correct answer should be 157065.67. Then I calculated…
TobiSonne
  • 1,044
  • 7
  • 22
2
votes
3 answers

R: How to stop rounding percentages to 0 decimal places on plotly chart?

I'm trying to add a plot to my shiny dashboard. The y-axis variable is a proportion and I want to format this as a percentage. I've discovered I can do it using the tickformat feature in the yaxis setting of the layout. However, since the…
Wolff
  • 1,051
  • 3
  • 18
  • 31
2
votes
2 answers

Java - rounding double to 2 decimal places

I know this question has been asked many times but I'm stuck and I don't know what the correct solution should be. I'm writing a program and there's a lot of numbers multiplication. The result must be rounded to 2 decimal places but sometimes the…
kertoip
  • 35
  • 7
2
votes
2 answers

Is this a malfunction of the ROUND function in MariaDB?

In a project I am working on, I somewhat found myself doing the same computation at back end and front end. The computation is rounding off the product of a ratio of two numbers and another number i.e. the expression to round of is of the form x /…
owino
  • 151
  • 1
  • 3
  • 11
2
votes
1 answer

Rounding errors for very large numbers in python

Rounding obscenely large numbers with a lot of decimals gives an error. What's the limit on this type of decimal rounding? I'm very much a beginner with Python so I'm not sure if there's another way around this. from decimal import…
nmpereira
  • 43
  • 3
2
votes
1 answer

Python rounding with Decimal module to specified decimal places

Question: How could I make Python's Decimal module round to a specified decimal place instead of rounding to a specified precision (significant figure) while evaluating an arithmetic operation? Info I have been using the Decimal module in Python to…
user12128336
2
votes
1 answer

bitwise stochastic rounding

I have this piece of C code that does stochasting rounding of a binary64 value to a binary32. Problem is I don't quite fully understand the code. I know it operates directly on the bits of a floating-point number, but I can't grasp what's happening.…
2
votes
1 answer

Converting from IEEE-754 to Fixed Point with nearest rounding

I am implementing a converter for IEEE 754 32 bits to a Fixed point with S15.16 in a FPGA. The IEEE-754 standard represent the number as: Where s represent the sign, exp is the exponent denormalized and m is the mantissa. All these values…
Diego Ruiz
  • 187
  • 2
  • 11
2
votes
3 answers

Round according to nearest decimal value - java

I have used this one Math.round(input * 100.0) / 100.0; but it didn't work with my requirement. I want to round into two decimal points according to nearest decimal value. firstly I want to check fourth decimal value if it is 5 or above I want to…
max
  • 65
  • 7
2
votes
1 answer

Delphi's Round() appears to be non-deterministic

I'm facing the bizarre situation that the same program on the same machine doing a Round() of the same floating point value does not always give the same result. At first I thought it has to be glitch because of a bit flip or something, but it keeps…
Thijs van Dien
  • 6,516
  • 1
  • 29
  • 48
2
votes
0 answers

Avoid rounding with std::setprecision

the following example int main(int argc, const char * argv[]) { std::stringstream ss; ss << std::fixed << std::setprecision(5) << 4567.9000990; cout << ss.str() << endl; } And when I run it the output is: 4567.90010 I was expecting the…
2
votes
3 answers

Not sure how to deal with repeating decimals in C

int number = round(2/3); printf("%i", number); the output is 0 I expected to get 1 as 0.6 recurring should round up - i know for sure that the problem is with recurring decimals as they are always rounded down - I'm not sure how to round up in…
Dev
  • 31
  • 4