rounding

How to Round in MS Access, VBA

Whats the best way to round in VBA Access? My current method utilizes the Excel method Excel.WorksheetFunction.Round(... But I am looking for a means that does not rely on Excel. ...

How to round a number to n decimal places in Java

What I'd like is a method to convert a double to a string which rounds using the half-up method. I.e. if the decimal to be rounded is a 5, it always rounds up the previous number. This is the standard method of rounding most people expect in most situations. I also would like only significant digits to be displayed. That is there should...

How to resolve a Java Rounding Double issue

Seems like the subtraction is triggering some kind of issue and the resulting value is wrong. double tempCommission = targetPremium.doubleValue()*rate.doubleValue()/100d; 78.75 = 787.5 * 10.0/100d double netToCompany = targetPremium.doubleValue() - tempCommission; 708.75 = 787.5 - 78.75 double dCommission = request.getPremium().do...

rounding to an arbitrary number of significant digits

How can you round any number (not just integers > 0) to N significant digits? For example, if I want to round to 3 significant digits, I'm looking for a formula that could take: 1,239,451 and return 1,240,000 12.1257 and return 12.1 .0681 and return .0681 5 and return 5 Naturally the algorithm should not be hard-coded to only handl...

Is it correct to compare two rounded floating point numbers using the == operator?

Or is there a chance that the operation will fail? Thanks. I chose the wrong term and what I really meant was rounding to 0, not truncation. The point is, I need to compare the integer part of two doubles and I'm just casting them to int and then using ==, but, as someone pointed out in one of my earlier questions, this could throw an...

How do I round a number in javascript?

Hey all. While working on a project, I came across a js-script created by a former employee that basically creates a report in the form of Name : Value Name2 : Value2 etc... Problem for me though, is that the values can sometimes be floats (with different precision), integers, or even in the form "2.20011E+17" What I outputted thoug...

Matching FORTRAN rounding in C#

FORTRAN provides several functions to convert a double precision number to an integral value. The method used for truncation/rounding differs. I am converting complex scientific algorithms which use these. According to FORTRAN documentation: aint(x) returns the integral value between x and 0, nearest x. anint(x) returns the nearest in...

How to Round a Time in T-SQL

I'me looking for a function that would receive a time and would round it to the next/previous hour / half-hour / quarter / minute. ...

Integer math in c#

I have a menu of product brands that I want to split over 4 columns. So if I have 39 brands, then I want the maximum item count for each column to be 10 (with a single gap in the last column. Here's how I'm calculating the item count for a column (using C#): int ItemCount = Convert.ToInt32(Math.Ceiling(Convert.ToDecimal(BrandCount) / ...

How do you round a number to two decimal places in C#?

I want to do this using the Math.Round function ...

How do I round a number up in PHP?

I need to round any non-integers up to the nearest integer, regardless of whether the number after the decimal place is >5 or not. Thanks! ...

floating point rounding detection

Hello, I'm using java and referring to the "double" datatype. To keep it short, I'm reading some values from standard input that I read in my code as doubles (I would much rather use something like BigInteger but right now it's not possible). I expect to get double values from the user but sometimes they might input things like: 999999...

Rounding negative numbers in Java

According to Wikipedia when rounding a negative number, you round the absolute number. So by that reasoning, -3.5 would be rounded to -4. But when I use java.lang.Math.round(-3.5) returns -3. Can someone please explain this? ...

C#: How do I do simple math, with rounding, on integers?

i want the result of an equation rounded to the nearest integer. e.g. 137 * (3/4) = 103 Consider the following incorrect code. int width1 = 4; int height1 = 3; int width2 = 137; int height2 = width2 * (height1 / width1); What is the proper way to perform "integer" math in C#? Do i really have to do: int height2 = (int)Math.Rou...

Different answer when converting a Double to an Int - Java vs .Net

In C# if I want to convert a double (1.71472) to an int then I get the answer 2. If I do this in Java using intValue() method, I get 1 as the answer. Does Java round down on conversions? Why do the Java API docs have such scant information about their classes i.e. Returns the value of the specified number as an int. This may in...

Why does .NET use banker's rounding as default?

According to the documentation, the decimal.Round method uses a round-to-even algorithm which is not common for most applications. So I always end up writing a custom function to do the more natural round-half-up algorithm: public static decimal RoundHalfUp(this decimal d, int decimals) { if (decimals < 0) { throw new Ar...

Integer division rounding with negatives in C++

Suppose a and b are both of type int, and b is nonzero. Consider the result of performing a/b in the following cases: a and b are both nonnegative. a and b are both negative. Exactly one of them is negative. In Case 1 the result is rounded down to the nearest integer. But what does the standard say about Cases 2 and 3? An old draf...

VBA: How to round to nearest 5? (or 10 or X)

Given numbers like 499, 73433, 2348 what VBA can I use to round to the nearest 5 or 10? or an abitrary number? By 5: 499 -> 500 2348 -> 2350 7343 -> 7345 By 10: 499 -> 500 2348 -> 2350 7343 -> 7340 etc. Integrated Answer X = 1234 'number to round N = 5 'rounding factor round(X/N)*N 'result is 1235 For floating point t...

How to write a prototype for Number.toFixed in JavaScript?

I need to round decimal numbers to six places using JavaScript, but I need to consider legacy browsers so I can't rely on Number.toFixed The big catch with toExponential, toFixed, and toPrecision is that they are fairly modern constructs not supported in Mozilla until Firefox version 1.5 (although IE supported the methods since vers...

C# Round Value of a Textbox

I have a small calculator that I am creating in C# (Sharp Develop). The user enters two values and the code returns the third. I am having trouble rounding the third value once it is returned. I have been through a couple of forums and the msdn site and I understand the code that is posted there, but I cant seem to make it work in my sit...