T-SQL: Rounding up to quarters

In a report where I output hours on service contracts, I need to round my contract hours up. Currently I'm getting my "Contract Hours" field from Navision. I add 10% (company policy) on these hours and this results in a number of hours which we can ...
more »

2017-10-05 16:10 (1) Answers

Round to nearest of specified numbers in Python?

Is it possible to round a number to the nearest of a few pre defined numbers? It would probably look something like round(x,3,6,13), where it rounds x to the nearest of the specified numbers. So you would get: x = 4 round(x,3,6,13) = 3 x =...
more »

2017-10-04 22:10 (0) Answers

Round Only Percentages to Nearest Multiple of 5

I have a CSV file that contains some values. I need to round only each of the percentages in the text file, to the nearest integer of 5. file 25,83%,22%,67%,43%,30,18%,2,11% awk Code: awk '{for (i=1; i<=NF; i++) $i = int( ($i+2) / 5) * 5 "%" ...
more »

2017-09-15 12:09 (0) Answers

Round Numerical Values to Nearest Multiple of 5

I have a text file with one line of percentages. I need to round all of the numbers in the text file to the nearest integer of 5, for example... 4 rounds up to 5, 8 rounds up to 10, 12 rounds down to 10, 17 rounds down to 15, etc... Text File: 25%...
more »

2017-09-15 11:09 (4) Answers

Sketch Export SVG with integer values

When I export SVG from MAC Sketch App I have 2 issues : 1) Remove unwanted tags <!-- Generator: Sketch 40 (33762) - http://www.bohemiancoding.com/sketch --> <title>Combined Shape</title> <desc>Created with Sketch.</desc&...
more »

2017-08-12 20:08 (0) Answers

Rounding float to int

Self studying coding (noob here), the answer to a practice problem is as follows: amount = (int) round (c); Where c is a float. Is it safe to say that this line converts the float to an integer through rounding? I tried researching methods of conv...
more »

2017-07-30 22:07 (3) Answers

How to round to specific values in Python

I am working on an algorithm to automatically create character sheets for a roleplaying game. In the game, you have attributes which you put points into to increase them. However, at a certain value it takes 2 points to increase the value of the actu...
more »

2017-07-26 17:07 (4) Answers

Pandas Shift Converts Ints to Float AND Rounds

When shifting column of integers, I know how to fix my column when Pandas automatically converts the integers to floats because of the presence of a NaN. I basically use the method described here. However, if the shift introduces a NaN thereby conve...
more »

2017-07-06 17:07 (1) Answers

I do *not* want correct rounding for function exp

The GCC implementation of the C mathematical library on Debian systems has apparently an (IEEE 754-2008)-compliant implementation of the function exp, implying that rounding shall always be correct: (from Wikipedia) The IEEE floating point standa...
more »

2017-06-03 18:06 (3) Answers

Nice way to truncate an integer

I have a function which is given a buffer which accepts to be filled up to a size_t length; however, the actual call which fills it wants an int as max length. So, in case the parameter cannot fit in an integer, I want it truncated to the maximum v...
more »

2017-04-06 14:04 (1) Answers

Python 3 code - Rounding integers

I am trying to round numbers up in python 3. In my existing code, the number either round up to the nearest 10 or down. For example, 67 goes to 70 and 64 goes to 60. I would like the number to always round up to the nearest multiple of 10, so that 67...
more »

2017-01-04 23:01 (1) Answers

Round off to next 0.05 in SQL Server

I have a requirement, where I need the rates to be rounded off to nearest nickel. For e.g: Rate . . . . Rounded Value 1.90 . . . . 1.90 1.91 . . . . 1.95 1.92 . . . . 1.95 1.93 . . . . 1.95 1.94 . . . . 1.95 1.95 . . . . 1.9...
more »

2016-12-29 10:12 (1) Answers

SQL Server numbers rounding issue

This is a follow-up question to [TSQL number rounding issue. It's the same code: IF OBJECT_ID(N'dbo.rounding_testing') IS NOT NULL DROP FUNCTION dbo.rounding_testing; GO CREATE FUNCTION dbo.rounding_testing ( @value FLOAT, @digit INT ) R...
more »

2016-12-21 03:12 (1) Answers

Why does C# round (100-1)/2 to 49 instead of 50?

According to my calculator: (100-1) / 2 = 49.5 If I have an int like this: int mid = (100 - 1) / 2 And printing mid will give me: 49 Why will C# give me 49 instead of 50? Aren't you supposed to round to the next whole number if it is .5 so tha...
more »

2016-11-16 00:11 (3) Answers

What does "number | 0" mean in Javascript?

I saw someone use this as a replacement for Math.floor() and was curious what it means and how it works. i.e. instead of doing: answer = Math.floor(number/2); they had: answer = number/2 | 0; Tried to search for it online and within SO but cou...
more »

2016-09-09 23:09 (0) Answers

Round-off / round-up criteria in Python

I'm porting a MATLAB code to Python 3.5.1 and I found a float round-off issue. In MATLAB, the following number is rounded up to the 6th decimal place: fprintf(1,'%f', -67.6640625); -67.664063 In Python, on the other hand, the following number is ...
more »

2016-08-27 17:08 (1) Answers

Using round() function in c

I'm a bit confused about the round() function in C. First of all, man says: SYNOPSIS #include <math.h> double round(double x); RETURN VALUE These functions return the rounded integer value. If x is integral, +0, -0, NaN, or infin...
more »

2016-08-25 17:08 (2) Answers

Rounding some numbers, and converting some to int

I made a method that takes two numbers and returns a calculated value rounded to three decimals. I'm curious to know how I can have numbers such as 1.141 to be rounded but numbers like 5.0 turned into integers (5). code: def calculateHypotenuse(a,b...
more »

2016-07-31 17:07 (1) Answers

rounding errors in Python floor division

I know rounding errors happen in floating point arithmetic but can somebody explain the reason for this one: >>> 8.0 / 0.4 # as expected 20.0 >>> floor(8.0 / 0.4) # int works too 20 >>> 8.0 // 0.4 # expecting 20.0 19.0 ...
more »

2016-07-26 13:07 (5) Answers

rounding 1 to have two floating digits

''' Your task is to write a function which returns the sum of following series upto nth term(parameter). Series: 1 + 1/4 + 1/7 + 1/10 + 1/13 + 1/16 +... ''' Kind of non-trivial but I tried to use round(1,2) to show 1.00 but it shows 1.0, what can ...
more »

2016-06-21 08:06 (2) Answers