I am trying to round up decimals to specific values in the following way:
1. 12.12 ---> 12.25
2. 12.5 ---> 12.5
3. 12.59 ---> 12.75
4. 12.75 ---> 12.75
5. 12.77 ---> 13
So they should be rounded up to the decimals .25, .5 and .75 or integer.
Is there an Excel function which can do this?
Please try:
=ROUNDUP(4*A1,0)/4
Your question uses positive numbers for sample data but there is a primary difference involving how negative numbers are handled by the CEILING function and the ROUNDUP function that should be mentioned.
This has to do with the way that ROUNDUP rounds away from zero and CEILING rounds to the numerically larger¹ number
The formulas in C2:D2 are:
=CEILING(A2, 0.25) ◄ C2
=ROUNDUP(A2*4, 0)/4 ◄ D2
Note the differences in the 7th, 9th and 11th rows. This is the difference in how the two functions handle rounding negative numbers. If you wanted the results in column C to follow the values in column D, you would have to use the following for negative numbers.
=CEILING(A2, -0.25) ◄ C2
But that doesn't work properly on positive numbers. While you could write a conditional statement that changed the sign of the significance parameter, it's a lot easier to choose what you want to happen with negative numbers and use either CEILING or ROUNDUP as the case may be.
¹If you get several mathematicians in a room and ask them if -1 is higher, larger or greater than -2, you will start World War III so I'm not going down that rabbit hole. The differences between CEILING and ROUNDUP are probably intended to cover both sides of the argument.
All of this can be related to the ROUNDDOWN function and the FLOOR function as well.
If you are only rounding to a fractional significance and not rounding in one direction or another, the MROUND function is another possibility.
Related
I am trying to use Microsoft Excel to format a large set of data. The data is all in decimal format and the results are paired so that we have 2 values per record. The first value is a Mass in grams, and the second value is the Uncertainty of that mass also in grams.
For example:
SampleName = S1, Mass(g) = 28.695, Uncertainty(g) = 1.601133
What I need to do is have the "Uncertainty" update to 2 significant figures, then depending on the value returned, have the "Mass" update to match the number of decimal places (or whole numbers) that the "Uncertainty" now is.
e.g.
if Uncertainty became 1.6, then Mass should become 28.6
if Uncertainty became 1.61, then Mass should become 28.69
if Uncertainty became 2, then Mass should become 29
I have attempted to use the ROUND function on the "Uncertainty" cell but then I don't know how to make the "Mass" cell update accordingly.
I have tried the following 2 ROUND formulas, which both seem to work for rounding the "Uncertainty":
=ROUND(A1,2-INT(LOG(ABS(A1))))
=ROUND(A1, 2)
Any help would be much appreciated.
This formula counts the number of decimal places in a given cell:
=LEN(RIGHT(A1,LEN(A1)-FIND(".",A1)))
So you could use this in your Round formula where you specify the number of decimals:
=ROUND(A1, LEN(RIGHT(A1,LEN(A1)-FIND(".",A1))))
To round to 2 significant figures you can use something like this:
=ROUND(uncertainty,2-(1+INT(LOG10(ABS(number)))))
To round (eg) B2 based on number of decimals in (eg) D2:
=ROUND(B2,IFERROR(LEN(RIGHT(D2,LEN(D2)-FIND(".",D2))),0))
For example, Anything between #.0 & #.02 will round down to #. Anything between #.2 & #.99 will round up to the nearest #.
I'm using the pound sign to indicate that the leading number should not have any effect on the result, but rather will be affected by the first decimal place.
8.1 should round to 8
8.21 should round to 9
17.1 should round to 17
17.8 should round to 18
etc.
I basically need to modify the standard .5 rounding rule to operate the same way but to use .2 as the cut off.
Hopefully I am not cutting the legs out from underneath me with this criteria, but I am looking for a formula/formatting solution only (non-VBA)
You can add a bias to your tested value to get the effect you want:
ROUND(value + 0.3, 2)
To round up earlier, and hold to two decimal places. Adding a bias this way allows you to control rounding (up) and exploit the built-in behavior of the built-in formula.
With a value in C1, in another cell enter:
=IF(C1-INT(C1)<=0.2,0,1)+INT(C1)
Please anyone can share your opinion excel how to calculate the PI() value.
In Execl while Calculating =TAN(30*PI()) formula it returns -1.07809E-14.If i directly give the PI() Value(3.141593) it returns 1.03923E-05.
It's almost certainly not calculated at all, but simply stored as a constant at the maximum significance for the machine.
That's pretty certainly more than six decimal places.
Here's the first 20 digits, try putting that in: 3.14159265358979323846
The accuracy or otherwise of Excel's value for π is perhaps less of the issue here than that of Excel's TAN function. TAN takes an argument in radians and 30*PI() is the same angle as 2*PI(), ie 360 degrees (a complete circle - though it might be argued that 30*PI() is a circle after 15 complete turns). The tangent of 360o is 0 (or at least the tangent tends to 0 as the angle approaches 360o) hence whatever the accuracy chosen for π, any answer other than 0 is incorrect.
-1.07809E-14 is nearer 0 than 1.03923E-05 because as has been pointed out, Excel is normally accurate to at least 14 digits and PI() as 3.14159265358979 is more accurate than pi as 3.141593. However -0.0000000000000107809 is nevertheless inaccurate at the 14th decimal place.
A more sensible comparison may be between the tangent of 30o with PI() and 3.141593:
=TAN(30*PI()/180) = 0.57735026918963
=TAN(30*3.141593/180) = 0.57735034616967
To 7 DP the answers are the same.
Excel evaluates 30 times PI() as 94.2477796076938 whereas 30*3.14159265358979 as 94.2477796076937.
Microsoft lists the following:
MS Excel PI function
PI function
Description
Returns the number 3.14159265358979, the mathematical constant pi, accurate to 15 digits.
you can see this by typing:
=pi()
then increasing the decimal places until you see zeros eg:
3.14159265358979000000
I want to round off the value in Excel when the value is greater than 5 after decimal.
For example:
if num= 9.15, result= 9.1
if num= 9.16, result = 9.2
Although your need contradicts the currently valid rounding rules it could be achieved with the following formula:
=TRUNC($A1*10^1+0.4*SIGN($A1))/10^1
The value in A1 can be any decimal value in any length either positive or negative. It will be "rounded" to 1 decimal place. The 10^1 part in the formula leads to rounding to 1 decimal place. Use 10^2 to round to 2 decimal places and so on.
For the second decimal place, I was going to post
=IF(AND(FIND(".",A2&".")=(LEN(A2)-2),RIGHT(A2)="5"),--LEFT(A2,LEN(A2)-1),ROUND(A2,1))
(modified according to #Jasen's comment)
A very simple approach is
=ROUND(A4-10^-10*SIGN(A4),1)
which should be fine up to several places of decimals if you change the number of decimals to round (but will fail because of rounding errors if the numbers are too large).
This also gives good results over a wide range of numbers:-
=ROUND(A2-A2/10^12,1)
To generalise the first one a bit more you could try
=IF(ISNUMBER(FIND(".",A2)),IF(RIGHT(A2)="5",--LEFT(A2,LEN(A2)-1),ROUND(A2,LEN(A2)-FIND(".",A2)-1)),A2)
to round the last decimal place down if it's a 5.
this should do it
=ceil(A1*10-0.5)/10
I'm in need of a formula that rounds numbers differently depending on if the number is tens, hundreds, thousands, hundred-thousands, millions, etc. I know the basic rounding functions in Excel but not sure how to do this exactly.
Examples:
1 - 999 need to be rounded up to the nearest 10.
1.000 - 99.999 need to be rounded up to the nearest 100.
100.000 - 999.999 need to be rounded up to the nearest 1.000.
1.000.000 - 999.999.999 need to be rounded up to the nearest 100.000.
1.000.000.000 - 999.999.999.999 need to be rounded up to the nearest 1.000.000
And all this in single formula that can easily be copied down.
Any help would be greatly appreciated!
You can use ROUNDUP function with a LOOKUP function nested to give you the logic you need, i.e. with values in A2 down use this formula in B2 copied down
=ROUNDUP(A2,LOOKUP(A2,10^{0,3,5,6,9},-{1,2,3,5,6}))
This part
10^{0,3,5,6,9}
defines the lower bound of each range. And this part:
-{1,2,3,5,6}
gives the number of digits to round to, e.g. -2 gives next 100, -3 next 1000 etc.
This rounds up to the nearest multiple of 100 etc. so 134 will round to 140. If you want to round to the nearest multiple then you can use the exact same formula but with ROUND in place of ROUNDUP
Probably the best way to do it would be a custom VBA function switching between values - That would give you the most amount of control, but you could do it with nested IF() statements too:
=IF(A1<1000,CEILING(A1,10),IF(A1<100000,CEILING(A1,100),IF(A1<1000000,CEILING(A1,1000),IF(A1<1000000000,CEILING(A1,100000),CEILING(A1,1000000)))))
Hope that helps!!