rounding

SQL Rounding Question

I have the following values being returned in a column.. 0.250000 and 13.000000. I'd like to round the 0.250000 up to 1 and leave the 13 as is. Any easy way to do this since they both fall within the same column? ...

Round a double to x significant figures after decimal point

If I have a double (234.004223) etc. I would like to round this to x significant digits after the decimal places in C# So far I can only find ways to round to x decimal places but this simply removes the precision if there are any 0s in the number. e.g. 0.086 to 1 decimal place becomes 0.1 but I would like it to stay 0.08. Thanks ...

How do you round a Double down to the nearest integer in VB .NET?

How do you round a Double down to the nearest integer in VB .NET? ...

.NET method to round a number up to the nearest multiple of another number?

I'm looking for a method that can round a number up to the nearest multiple of another. This is similar Quantization. Eg. If I want to round 81 up to the nearest multiple of 20, it should return 100. Is there a method built-in method in the .NET framework I can use for this? The reason I'm asking for a built-in method is because the...

Limiting a date range with exactness in MS SQL / SQL Server 2005

I want to limit a report to return records from Date A through Date B. This is what I have been doing: declare @startDate varchar(20) declare @endDate varchar(20) set @startDate = '01/01/2008' set @endDate = '04/01/2008' -- test what are the start and end dates select min(date),max(date) from view_Inspections where date between @startD...

rounding shortcuts in C

I am working in C to implement pseudo-code that says: delay = ROUND(64*(floatDelay - intDelay)) where intDelay = (int) floatDelay The floatDelay will always be positive. Is there an advantage to using the round function from math.h: #inlcude <math.h> delay=(int) round(64*(floatDelay-intDelay)); or can I use: delay=(int)(64*(floatD...

Should I use NSDecimalNumber to deal with money?

As I started coding my first app I used NSNumber for money values without thinking twice. Then I thought that maybe c types were enough to deal with my values. Yet, I was advised in the iPhone SDK forum to use NSDecimalNumber, because of its excellent rounding capabilities. Not being a mathematician by temperament, I thought that the m...

In jQuery, what's the best way of formatting a number to 2 decimal places?

This is what I have right now: $("#number").val(parseFloat($("#number").val()).toFixed(2)); It looks messy to me. I don't think I'm chaining the functions correctly. Do I have to call it for each textbox, or can I create a separate function? ...

round() for float in C++

I need a simple floating point rounding function, thus: double round(double); round(0.1) = 0 round(-0.1) = 0 round(-0.9) = -1 I can find ceil() and floor() in the math.h - but not round(). Is it present in the standard C++ library under another name, or is it missing?? ...

Java: Round to arbitrary values

In Java, how do I round to an arbitrary value? Specifically, I want to round to .0025 steps, that is: 0.032611 -> 0.0325 0.034143 -> 0.0350 0.035233 -> 0.0350 0.037777 -> 0.0375 ... Any ideas or libs? ...

Is there a function to round a float in C or do I need to write my own?

Is there a function to round a float in C or do I need to write my own? float conver= 45.592346543; Would like to round actual value to one decimal place. conver = 45.6 Thanks. ...

How to round a Column defined as Float on INSERT and UPDATE in SQL Server 2005

I am working on a Database that uses the Float data type to store values that should only be 2 decimal positions (dollars and cents). Using Float appears to work OK, as long as the person updating the Float column does a ROUND. Of course, this does not always happen and then when a SUM is done it is always off a few pennies from what is ...

How do I round up currency values in Java?

Okay, here's my problem. Basically I have this problem. I have a number like .53999999. How do I round it up to 54 without using any of the Math functions? I'm guessing I have to multiply by 100 to scale it, then divide? Something like that? Thanks guys! EDIT: more info The issue is with money. let's say I have $50.5399999 I know ho...

Convert/Quantize Float Range to Integer Range

Say I have a float in the range of [0, 1] and I want to quantize and store it in an unsigned byte. Sounds like a no-brainer, but infact it's quite compliated: The obvious solution looks like this: unsigned char QuantizeFloat (float a) { return (unsigned char) (a * 255.0f); } This works in so far that I get all numbers from 0 to 25...

How might I convert a double to the nearest integer value?

how do you convert a double into a int (can remove the rounding) ...

Rounding a Java BigDecimal to the nearest interval

I have a BigDecimal calculation result which I need to round to the nearest specified interval (in this case it's the financial market tick size). e.g. Price [Tick Size] -> Rounded Price 100.1 [0.25] -> 100 100.2 [0.25] -> 100.25 100.1 [0.125] -> 100.125 100.2 [0.125] -> 100.25 Thanks. Update: schnaader's solution, translated into J...

How do I do floating point rounding with a bias (always round up or down)?

I want to round floats with a bias, either always down or always up. There is a specific point in the code where I need this, the rest of the program should round to the nearest value as usual. For example, I want to round to the nearest multiple of 1/10. The closest floating point number to 7/10 is approximately 0.69999998807, but th...

Why does the order affect the rounding when adding multiple doubles in C#

Consider the following C# code: double result1 = 1.0 + 1.1 + 1.2; double result2 = 1.2 + 1.0 + 1.1; if (result1 == result2) { ... } result1 should always equal result2 right? The thing is, it doesn't. result1 is 3.3 and result2 is 3.3000000000000003. The only difference is the order of the constants. I know that doubles are impl...

Why does SQL Server round off results of dividing two integers?

I have a table with a smallint column that contains percentages as whole numbers (i.e., 50, 75, 85, etc.) When I divide this column by 100, as in SELECT MY_COLUMN/100 AS PCT_AS_FRACTION FROM MY_TABLE the result is rounded to the nearest whole number. For example, for a row that contains the number "50", I get zero as my result. I ca...

Rounding numbers in Objective-C

Hi, I'm trying to do some number rounding and conversion to a string to enhance the output in an Objective-C program. I have a float value that I'd like to round to the nearest .5 and then use it to set the text on a label. For example: 1.4 would be a string of: 1.5 1.2 would be a string of: 1 0.2 would be a string of: 0 I've spe...