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

Need both Celsius and Fahrenheit with WeatherKit

I have a weather app that tells the temperature in Celsius and Fahrenheit at the same time. I'd like to use WeatherKit, but I'm having trouble rounding Celsius down to no decimal places. I can do it with Fahrenheit with .formatted because I'm based…
BenG94
  • 23
  • 5
2
votes
0 answers

BigDecimal rounding when not knowing desired scale

i know how rounding BigDecimal with the API, but i actually work witjh a remote API which sends to me unformated and not rounded BigDecimals. As examples, the API back-end returns to me 3.70000000000000017763568394002504646778106689453125 which…
2
votes
1 answer

Round to the nearest odd multiple of a number

is there a MATLAB function that can round to the nearest odd multiple of a number? For instance, if x = 1.1 and the number is 0.5, then x should be rounded to 1.5 I could come up with a function to round to the nearest multiple but not the nearest…
2
votes
1 answer

How can I execute a custom round in SQL by 0.25 increments?

I'm trying to create a custom round in SQL that rounds up or down by .25 but I'm not certain if this is actually possible with what I'm trying to accomplish. I've tried the ROUND statement but it seems you can only specify the number of decimal…
Dr.Prog
  • 229
  • 3
  • 13
2
votes
0 answers

ToString rounding change in core 3.1

The output of the code below changed from "2.0" in .NET 4.7.2 to "1.9" in Core 3.1 Console.WriteLine((1.95).ToString("N1")); I think this may be related to…
innominate227
  • 11,109
  • 1
  • 17
  • 20
2
votes
1 answer

Snowflake 2 decimal places

I have a data column that is a number and it has nulls, dashes, and commas. I want to remove all and replace with 0.00. Also I have some numbers that are 11.4 instead of 11.40. How do I fix this? also something either nvl or round adds the comma…
2
votes
1 answer

round error of C++ when using fixed and setprecision in stringstream

I wrote a program in C++ and I think the result of it should be 12.3 and 12.2. But the final result is 12.2 and 12.2. Obviously, it is not rounding rightly. But why? Thanking you very much :) #include #include using namespace…
Lee
  • 31
  • 3
2
votes
2 answers

Unnatural round prices

I need to round prices for my client in a non-common way : 120.28 => 120.2 130.23 => 130.2 150.64 => 150.6 The rule is to always keep the nearest lowest 1 precision. I try to use the round() method but all my tries are useless since this method…
Greco Jonathan
  • 2,517
  • 2
  • 29
  • 54
2
votes
2 answers

How do you round non double numbers in R?

I'd like to round some integer numbers in R. Of course i already know the round() method, but this only seems to work on the data type 'double' or 'float'. How can i round a normal integer without any decimal values, e.g 1445 --> 145 1526 -->…
luism
  • 33
  • 6
2
votes
1 answer

Rounding to the nearest nth decimal place with numpy

Can one use np.around to the nearest n-th decimal places? import pandas as pd import numpy as np df=pd.DataFrame({'num': [0.444, 0.445, 0.446, 0.4, 0.41, 0.49], 'near': [0.44, 0.45, 0.45, 0.4, 0.41, 0.49]}) df Out[199]: num…
aeiou
  • 337
  • 1
  • 7
2
votes
1 answer

Understand rounded results after division involving floating point types

In Postgres 14, I see rounded results that do not make sense to me. Trying to understand what is going on. In all cases I am dividing 19 by 3. Casting either integer value to a real: SELECT 19::real /3; yields a value of 6.333333333333333 SELECT…
2
votes
1 answer

How do I round a float number to a certain number of digits, in a portable way

Most of the time when someone asks how to round a float to a certain number of digits, the classic answer given is to use FORMAT : (format nil "~,2F" 6.376) ==> "6.38" However, in a particular case, the rounding using FORMAT is implementation…
Jérôme Radix
  • 10,285
  • 4
  • 34
  • 40
2
votes
0 answers

Trying to round last section to two decimal places in terms of discount

I cannot figure out rounding to two decimals for the cost with a discount and without a discount. print('You are welcome to the AMC Movie Theaters. There are three categories of ticket prices based on age:') print('1. Children (ages 2-12) costs…
2
votes
2 answers

What does "double + 1e-6" mean?

The result of this cpp is 72.740, but the answer should be like 72.741 mx = 72.74050000; printf("%.3lf \n", mx); So I found the solution on website, and it told me to add "+1e-7" and it works mx = 72.74050000; printf("%.3lf \n", mx + 1e-7); but I…
Ank H
  • 23
  • 5
2
votes
1 answer

Symmetric band matrix vector multiplication

Trying to multiply symmetric band matrix times vector, i.e. simple multiplication A*x = b where A is symmetric band matrix, stored in format as here. So the lower part of it is not saved into the storage. cols is a vector containing the indices of…
2Napasa
  • 378
  • 1
  • 5
  • 17