How to roundup a number to the closest ten? - excel

Probably the title is not very suggestive.
Let me explain you with an example. I have:
12345.6
2345.1
12345.00000001
I want those numbers to be roundup to 12350.
How can I do this?
If possible, I would rather use formulas instead of VBA.

You could also use CEILING which rounds up to an integer or desired multiple of significance
ie
=CEILING(A1,10)
rounds up to a multiple of 10
12340.0001 will become 12350

Use ROUND but with num_digits = -1
=ROUND(A1,-1)
Also applies to ROUNDUP and ROUNDDOWN
From Excel help:
If num_digits is greater than 0 (zero), then number is rounded to the specified number of decimal places.
If num_digits is 0, then number is rounded to the nearest integer.
If num_digits is less than 0, then number is rounded to the left of the decimal point.
EDIT:
To get the numbers to always round up use =ROUNDUP(A1,-1)

You can use the function MROUND(<reference cell>, <round to multiple of digit needed>).
Example:
For a value A1 = 21 round to multiple of 10 it would be written as
=MROUND(A1,10)
for which Result = 20
For a value Z4 = 55.1 round to multiple of 10 it would be written as
=MROUND(Z4,10)
for which Result = 60

the second argument in ROUNDUP, eg =ROUNDUP(12345.6789,3) refers to the negative of the base-10 column with that power of 10, that you want rounded up. eg 1000 = 10^3, so to round up to the next highest 1000, use ,-3)
=ROUNDUP(12345.6789,-4) = 20,000
=ROUNDUP(12345.6789,-3) = 13,000
=ROUNDUP(12345.6789,-2) = 12,400
=ROUNDUP(12345.6789,-1) = 12,350
=ROUNDUP(12345.6789,0) = 12,346
=ROUNDUP(12345.6789,1) = 12,345.7
=ROUNDUP(12345.6789,2) = 12,345.68
=ROUNDUP(12345.6789,3) = 12,345.679
So, to answer your question:
if your value is in A1, use
=ROUNDUP(A1,-1)

Related

How to round up the value end with Zero in asp.net mvc5

Hi i need to round up the value end with Zero (end value to be 0, like 450, 55000, 4560). i want to round up the value with ending zero eg if i got value like 102498 means round up value like 102500 and if i got value like 47504 means round up value like 47500 this i have to do in mvc eg values 999 =>1000 994=>990 995=>990 i have to do this roundup in table view page.
I'd suggest starting with:
Decimal value = 102498;
var rounded = Math.Round(value / 10, MidpointRounding.AwayFromZero) * 10;
Console.WriteLine(rounded);
The steps are:
Divide by 10
Round (.5 up, below .5 down - AwayFromZero)
Multiply by 10 (this ensures the last digit is always 0)

Odd value returned by LEN in EXCEL

Consider, for example, the following function strings inside some cells:
A1 = B1 - INT(B1)
A2 = LEN(A1)
A2 will return 17 regardless of the value returned by the function (and thus held) in A1. I suspect that this has to do with the precision returned by INT(B1), but I don't know enough of Excel's inner-mechanisms to confirm.
The end goal is to obtain the length of the decimal part of a number held in B1. For example, if B1 = 978.01194, A2 would hold 5 (LEN(01194)). Obviously this would require a subtraction of 2 to eliminate the counting of the leading (0.) in my implementation above, but that's assuming I can get proper results with this method. Any help or guidance in other methods would be greatly appreciated!
EDIT:I realized that the loss of proper precision occurs only when I subtract the two quantities. INT(B1) returns proper precision, and using its length I can obtain the decimal by subtracting from the original. Would still like to know what is causing the operation in A1 to lose precision internally for LEN.
Alternatives are to use number that is not result from a calculation :
= LEN(B1) - LEN( INT(B1) ) - 1
or round the number to less than 15.95 significant digits :
= LEN( ROUND( B1 - INT(B1), 16 - LEN(INT(B1)) ) ) - 2
= LEN(TEXT(B1,"0.##############")) - LEN(INT(B1)) - 1
Another alternative is to FIND where the decimal occurs and use that as an offset, e.g.
= LEN(B1)-FIND(".",B1)
In general, it is not wise to perform a mathematical operation on a number when what you are really interested in is the text that represents the number for this exact reason. Floating points are not very reliable for dealing with exactness which is why you are experiencing the extra trailing numbers after the decimal in this case.

Truncate to the nearest thousandths and ignore the remainder of the value

Can MS Excel do rounding but only up to the nearest thousandths place and ignore the rest of the decimals in a formula? I've tried value, fixed, round and none of these do what I need.
Let's say I have 100 square feet of space and I pay $1.00566399 per sq foot, I need the formula to round only up to the 5 and ignore the rest of the numbers because when you speak on longer terms it makes a difference in rate.
So I should be multiplying 100sf by $1.01 = $101.00 and not get 100sf * 1.00566399 = $101.57
=trunc(A1,5)
If you want to round up, maybe something like
=trunc((A1*10000+1)/10000,5)
Use the TRUNC($cellRef or number, Decimal places) function. It reduces the number of decimal places WITHOUT rounding, then do your math.
So for example:
=TRUNC(1.00566399,3)
=A1*ROUNDUP(B1,2)
Where A1 contains the number of square feet and B1 contains the price per square foot in it's original long decimal form.

Rounding error when using INT function

I have user input in two cells, named "UpperRangeHigh" and "UpperRangeLow". I have the following code:
dRangeUpper = [UpperRangeHigh] - [UpperRangeLow]
lLines = Int(dRangeUpper * 100 / lInterval)
The user inputs 120.3 and 120 into the input cells respectively. lInterval has the value 10. VBA produces the result of 2 for lLines, instead of 3.
I can overcome this problem by adding 0.000000001 to dRangeUpper, but I'm wondering if there is a known reason for this behaviour?
This appears to be a problem with Excel's calculation and significant digits. If you do:
=120.3 - 120 and format the cell to display 15 decimal places, the result appears as:
0.2999999999999970
Here is a brief overview which explains how Excel uses binary arithmetic and that this may result in results divergent from what you would expect:
http://excel.tips.net/T008143_Avoiding_Rounding_Errors_in_Formula_Results.html
You can overcome this by forcing a rounded precision, e.g., to 10 decimal places:
lLines = Int(Round(dRangeUpper, 10) * 100 / lInterval
Kindly use single or double when working with decimals to get more accurate results.
Sub sample()
Dim dRangeUpper As Double
dRangeUpper = CDbl("120.3") - CDbl("120")
lLines = Round(CDbl(dRangeUpper * 100 / 10), 4)
End Sub
output = 3
This is a known Floating point issue within Excel
http://support.microsoft.com/kb/78113
From MSDN:
To minimize any effects of floating point arithmetic storage
inaccuracy, use the Round() function to round numbers to the number of
decimal places that is required by your calculation. For example, if
you are working with currency, you would likely round to 2 decimal
places:
=ROUND(1*(0.5-0.4-0.1),2)
In your case, using round() instead of INT should do the trick using 0 rather than 2

how to convert this excel formula in english words?

can someone please translate this excel spreadsheet cell formula in english words ?
=ROUND(IF(F28 < 1568,2.5,IF(F28 < 2491,0.004873 * F28-5.142,0.02269*F28^0.7329)),2)
am creating a program based from that formula, but i don't understand which one will go first. atleast i understand this part IF(F28 is less than 1568) ...then what?
Start from the outer if statement and move inwards. The comma in the IF function separates the statements like :
boolean expression, true part, and false part
The following is the psuedo code of the above. All the Round are to two decimal places.
IF (F28 < 1568) THEN
ROUND (2.5)
ELSE IF (F28 < 2491) THEN
ROUND (0.004873 * F28 - 5.142)
ELSE
ROUND (0.02269 * F28^0.7329)
If the value in cell F28 is less than 1568, then the value in this cell will be 2.5 rounded to 2 decimal places - i.e. 2.5
If the value in cell F28 is 1568 or more, but less than 2491, then the value in this cell will be:
0.004873 multiplied by [the value in cell F28 minus 5.142], rounded to 2 decimal places
Otherwise (i.e. the value in cell F28 is 2491 or more) the value in this cell will be: 0.02269 multiplied by [the value in cell F28 to the power of 0.7329], rounded to 2 decimal places
You will round the following in this order:
Smaller than 1568 = 2.5
Bigger than/Equal 1568 but smaller than 2491 = 0.004873 * F28-5.142
Bigger than/Equal 2491 = 0.02269*F28^0.7329
Basically that means this:
IF F28 is smaller than 1568 then use 2.5
IF F28 is larger or equal to 1568 but smaller than 2491 then use 0.0004873 * F28 - 5.142
IF F28 is larger or equal to 2491 then use 0.02269 * F28^0.7329
Round the outcome to 2 digits.

Resources