rounding

Rounding a number down in VB

Hi I have a vb application that need to round a number down e.g. 2.556 would become 2.55 and not 2.26 I can do this using a function to strip off the characters more that 2 right from the decimal point using this: Dim TheString As String TheString = 2.556 Dim thelength = Len(TheString) Dim thedecimal = InStr(TheString, ".", CompareM...

Why do round() and ceil() not return an integer ?

Once in a while, I find myself rounding some numbers, and I always have to cast the result to an integer : int rounded = (int) floor(value); Why do all rounding functions (ceil(), floor()) return a floating number, and not an integer ? I find this pretty non-intuitive, and would love to have some explanations ! ...

How to use expr on float?

I know it's really stupid question, but I don't know how to do this in bash: 20 / 30 * 100 It should be 66,67 but expr is saying 0, because it doesn't support float. What command in Linux can replace expr and do this equalation? ...

Oracle Bankers rule

Why Oracle is not using Bankers rule (the rounding method)? ...

OpenGL: distorted textures when not divisible by 2

I have a game engine that uses OpenGL for display. I coded a small menu for it, and then I noticed something odd after rendering the text. http://img43.imageshack.us/i/garbagen.png/ As you see, the font is somewhat unreadable, but the lower parts (like "Tests") look as intended. Seems the position on the screen affects readability, as t...

c++ rounding of numbers away from zero

Hi i want to round double numbers like this (away from zero) in C++: 4.2 ----> 5 5.7 ----> 6 -7.8 ----> -8 -34.2 ----> -35 What is the efficient way to do this? ...

Rounding floats with non-exact representation

Hello, We have a problem with rounding of floating point numbers for some financial calculations. Basically, we want to round monetary amounts like 1000000000.555 to 2 decimals. However, the float representation of this number is 1000000000.5549999 and as a result we will round down to 1000000000.55 rather than the correct 1000000000.5...

javascript strange rounding problem

Hi, I have the following javascript function for rounding: function round(val, numberdigits){ return Math.round(val*Math.pow(10, numberdigits))/Math.pow(10, numberdigits); } In most of the cases, it does its job well, but in some rare cases, the returned value has one digit more, which is always a 5. Example list of results wi...

Rounding the result of division in Javascript

I'm performing the following operation in Javascript: 0.0030 / 0.031 How can I round the result to an arbitrary number of places? What's the maximum number that a var will hold? ...

Round time to nearest 15min interval in Excel

I've an excel spreadsheet with a column which has the date and time of a particular event. I would like to round this to the nearest 15 minute interval so that I can count the total number of events in this period. What is the best way to do do the rounding? ...

LINQ to SQL Math.Round Problem

Hello all, I'm having an issue with a query I wrote where for some reason the variable that I'm using to store a decimal value in returns 6 values after the decimal place (they're mostly 0). I have tried the following (and different combinations using Math.Round) with no luck. Sales = (from invhed in INVHEAD ......

Rounding off decimals in Django

I want to round off my decimal values as below: 7,715.625 becomes 7,716 How do I achieve this? ...

Rounding to even in C#

I'm not seeing the result I expect with Math.Round. return Math.Round(99.96535789, 2, MidpointRounding.ToEven); // returning 99.97 As I understand MidpointRounding.ToEven, the 5 in the thousandths position should cause the output to be 99.96. Is this not the case? I even tried this, but it returned 99.97 as well: return Math.Round(9...

How to round decimal value up to nearest 0.05 value??

Is there any way to round up decimal value to its nearest 0.05 value in .Net? Ex: 7.125 -> 7.15 6.66 -> 6.7 If its now available can anyone provide me the algo? ...

Rounding a double to 5 decimal places

How do I round a double to 5 decimal places, without using DecimalFormat? ...

Is this SQL code susceptible to rounding errors?

I have discovered some strange behavior where a stored procedure is returning inaccurate results by a penny or two. Here's the code (I didn't write it): ALTER PROCEDURE [dbo].[TN_GetSimpleBalance] @custID int, @nBalance decimal (8,2) output AS declare @ArBalance as decimal (8,2) declare @custStatusCode varchar (2) declare @u...

Is it possible to round a double using just a printf statement?

Obviously this is just a fraction of the code. printf("Please enter a positive number that has a fractional part with three or more decimal places\n"); scanf("%5.2d", &x); printf("The number you have entered is %5.2d\n" ,x); Would this automatically round the number I type in? Or is there another way to do this? Edit: printf("Please...

Sprintf in Ruby

Sort of a quick question. I'm writing: puts "%.3f %.4f %.5f" % [3.998877, 3.998877, 3.998877] and get the following output: 3.999 3.9989 3.99888 sprintf simply rounds the numbers. How do I restrict that rounding? ...

C# - Math.Round

Hello, I am trying to understand how to round to the nearest tenths position with C#. For instance, I have a value that is of type double. This double is currently set to 10.75. However, I need to round and then truncate everything past the tenths position. In this case, I am seeking a value of 10.8. How do I round to the tenths positio...

sin, cos, tan and rounding error

I'm doing some trigonometry calculations in C/C++ and am running into problems with rounding errors. For example, on my Linux system: #include <stdio.h> #include <math.h> int main(int argc, char *argv[]) { printf("%e\n", sin(M_PI)); return 0; } This program gives the following output: 1.224647e-16 when the correct answer ...