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

Either round or truncate pandas column values to 2 decimals, based on floor/ceil conditions

I have a data frame that I need to convert specifically to two decimal place resolution based on the following logic: if x (in terms of the value with more than two decimals places) > math.floor(x) + 0.5 ...then round this value to two…
Jake Walther
  • 79
  • 1
  • 1
  • 7
2
votes
3 answers

Generate random integer rounded to nearest whole number

I am wondering how to generate a random integer that gets rounded to nearest whole number, e.g. random number: 436, == 440, or 521, == 520. basically just rounding the random number to the nearest whole number. (JavaScript) Math.floor(Math.random()…
Ben
  • 31
  • 6
2
votes
0 answers

R: Trying to make a summary table and round the values

I am making a summary table in R and trying to round the values to 3 decimal places but the rounding is not happening for all of the columns. Here is my code #summarize the needed data achesy_data<-aches_young %>% group_by(age) %>% …
confused
  • 21
  • 2
2
votes
2 answers

C# implementation of T-SQL round function

I'm trying to reproduce in C# the behavior of the T-SQL Round function when a truncate function is used. This is the SQL behavior I'm trying to reproduce in C#: SELECT ROUND(150.757,2,0) -- 150.76 SELECT ROUND(150.757,2,1) -- 150.75 SELECT…
Pedro
  • 2,300
  • 1
  • 18
  • 22
2
votes
2 answers

C# to C++: Convert C# Time calculation to C++ chrono

I've got the task to convert some C# code to C++ and I've problems with chrono. Goal is to round a time to a variable time span. C#: int iRoundTo = 30; // can be 45 or other variable value, not a const DateTime dt = Floor(DateTime.Now, new…
Mighty
  • 33
  • 4
2
votes
2 answers

Help Importing an Excel File into MySQL using phpMyAdmin

I am uploading Excel files (.xls) containing numeric values such as 884.557 and 731.0547 into a MySQL database using phpMyAdmin's built-in Import function. However, I am having horrible rounding/truncation issues. For some reason, some values like…
user845454
  • 41
  • 1
  • 5
2
votes
1 answer

How to compute trunc(a/b) with only the nearest-to-even rounding mode?

Given two IEEE-754 double-precision floating-point numbers a and b, I want to get the exact quotient a/b rounded to an integer towards zero. A C99 program to do that could look like this: #include #include #pragma STDC FENV_ACCESS…
Řrřola
  • 6,007
  • 1
  • 17
  • 10
2
votes
3 answers

How do I set the precision of a float variable in c++

It will print 88.89 to the console because, 88.888 with a hundredths place rounding precision equals 88.89. How do I make "b" equal to the value of "a" rounded to the hundredths place. (e.g. 88.89) How do I make it so its like, | float b = "a"…
user17583950
2
votes
1 answer

Is it possible to show the actual exact count of likes in the layout style "box count" and not have the numbers rounded?

Is it possible to show the actual exact count of likes in the layout style "box count" for example 1019 not the rounded 1K in the like button on my homepage? I do not want to use the standard layout style. I want to use the box count. Is there a…
mmmmm83
  • 21
  • 1
  • 4
2
votes
1 answer

Greater than or equal to in Custom number format

I'm looking to custom format this values but when my result is 15.0 or 14.9 the formula doesn't work. I've tried to place <= or =< but the custom number format doesn't recognize it. Here is my current formula. [>15.0]0.0[color…
mau
  • 185
  • 11
2
votes
3 answers

Round Up Number Integer in SQL query

I have a query for round up for my stored procedure like this DECLARE @number int; SET @number = 918750; SELECT @number + (100 - @number % 100 ) This returns 918800 The correct value to be returned would be 918,800. But in case @number = 918800…
lass
  • 149
  • 1
  • 7
2
votes
2 answers

stepify / grid snap function for numerical array in python

Is there a function in python, numpy, pandas etc. to round a numpy array or pandas Series to certain steps like Godot's stepify does? float stepify ( float s, float step ) Snaps float value s to a given step. This can also be used to round a…
ascripter
  • 5,665
  • 12
  • 45
  • 68
2
votes
1 answer

F.3 Operations, 9 lists 5 FE_ macros followed by 4 IEEE 754 rounding-direction attributes ending up with "respectively": mistake?

N2479 C17..C2x working draft — February 5, 2020 ISO/IEC 9899:202x (E): F.3 Operations, 9: The macros (7.6) FE_DOWNWARD, FE_TONEAREST, FE_TONEARESTFROMZERO, FE_TOWARDZERO, and FE_UPWARD, which are used in conjunction with the fegetround and…
pmor
  • 5,392
  • 4
  • 17
  • 36
2
votes
1 answer

Magento 2 / Prices and subtotals with 4 decimals But VAT and Totals on 2 decimals

I had to change prices to 4 decimals and it's OK. However, i have sometimes rounded cent in totals which is wrong. The explanation is that all calculations (subtotal, VAT and total) are on 4 decimals then rounded to 2 decimals. With rounding,…
Aurel
  • 338
  • 2
  • 13
2
votes
1 answer

How to round a BigDecimal before the decimal?

I have a BigDecimal like this var a = new BigDecimal("1234.56") and I want to round it to commercially to two places before the decimal, so that I get something equivalent to var b = new BigDecimal("1200.00") so that (new…
peer
  • 4,171
  • 8
  • 42
  • 73