number-rounding

JavaScript: Rounding question

If I have the following var lowerBound = 0; var higherBound = 100; var inputVar = document.getElementById('input').value; // e.g. 51 How do I programatically determine if the inputVar is closer to variable lowerBound or variable higherBound? Meaning, if the user inputs '51', the function should return '100'. But if the user inputs '...

Why does .NET decimal.ToString(string) round away from zero, apparently inconsistent with the language spec?

I see that, in C#, rounding a decimal, by default, uses MidpointRounding.ToEven. This is expected, and is what the C# spec dictates. However, given the following: A decimal dVal A format string sFmt that, when passed in to dVal.ToString(sFmt), will result in a string containing a rounded version of dVal ...it is apparent that decim...

C++: Rounding up to the nearest multiple of a number

OK - I'm almost embarrassed posting this here (and I will delete if anyone votes to close) as it seems like a basic question. Is this the correct way to round up to a multiple of a number in C++? I know there are other questions related to this but I am specficially interested to know what is the best way to do this in C++: int round...

Java Rounding Up

How can I rould the value of the numberGrade up so if it is 89.5 it goes to 90. numberGrade is taken in as a double but making it a int does not round it up or down. public class GradeReporter { // The limit is the inclusive lower limit for each letter // grade -- this means that 89.5 is an 'A' not a 'B' public static final...