Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Rounding up based on a decimal value
I would like to be able to round a number based on a decimal value. For
example, if the result is 23.7, 23.8, or 23.9, I want the number to round up to 24. I always want to round up for .7 and higher. Is there a way to code this? |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Rounding up based on a decimal value
add 0.3, and rounddown
23.6 would be 23.9 - 23 23.7 would be 24.0 - 24 23.8 would be 24.1 - 24 so if values in a2,a3 etc b2=rounddown(a2+0.3) Steve On Mon, 27 Nov 2006 16:55:02 -0000, Kelley wrote: I would like to be able to round a number based on a decimal value. For example, if the result is 23.7, 23.8, or 23.9, I want the number to round up to 24. I always want to round up for .7 and higher. Is there a way to code this? |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Rounding up based on a decimal value
Thanks. If the result is .0, .1, .2, .3, .4, .5, or .6, I need the decimal
to stay. If the result is .7, I need it to round up to the nearest integer. It the result is .8, or .9, I need it to round to .1 or .2. "SteveW" wrote: add 0.3, and rounddown 23.6 would be 23.9 - 23 23.7 would be 24.0 - 24 23.8 would be 24.1 - 24 so if values in a2,a3 etc b2=rounddown(a2+0.3) Steve On Mon, 27 Nov 2006 16:55:02 -0000, Kelley wrote: I would like to be able to round a number based on a decimal value. For example, if the result is 23.7, 23.8, or 23.9, I want the number to round up to 24. I always want to round up for .7 and higher. Is there a way to code this? |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Rounding up based on a decimal value
That's not what you said the first time :)
a2 has value b2 = if((int(a2)-a2)<0.7,a2,a2+0.3) Steve On Mon, 27 Nov 2006 18:16:01 -0000, Kelley wrote: Thanks. If the result is .0, .1, .2, .3, .4, .5, or .6, I need the decimal to stay. If the result is .7, I need it to round up to the nearest integer. It the result is .8, or .9, I need it to round to .1 or .2. "SteveW" wrote: add 0.3, and rounddown 23.6 would be 23.9 - 23 23.7 would be 24.0 - 24 23.8 would be 24.1 - 24 so if values in a2,a3 etc b2=rounddown(a2+0.3) Steve On Mon, 27 Nov 2006 16:55:02 -0000, Kelley wrote: I would like to be able to round a number based on a decimal value. For example, if the result is 23.7, 23.8, or 23.9, I want the number to round up to 24. I always want to round up for .7 and higher. Is there a way to code this? -- Steve (3) |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Rounding up based on a decimal value
I think you meant =IF((A2-INT(A2))<0.7,A2,A2+0.3) which presumes that A20.
Also, You need to be a bit more careful about the impact of finite precision binary representations. For instance, if A2 contains 8.7, then ((A2-INT(A2))<0.7 is TRUE. Jerry "SteveW" wrote: That's not what you said the first time :) a2 has value b2 = if((int(a2)-a2)<0.7,a2,a2+0.3) Steve On Mon, 27 Nov 2006 18:16:01 -0000, Kelley wrote: Thanks. If the result is .0, .1, .2, .3, .4, .5, or .6, I need the decimal to stay. If the result is .7, I need it to round up to the nearest integer. It the result is .8, or .9, I need it to round to .1 or .2. "SteveW" wrote: add 0.3, and rounddown 23.6 would be 23.9 - 23 23.7 would be 24.0 - 24 23.8 would be 24.1 - 24 so if values in a2,a3 etc b2=rounddown(a2+0.3) Steve On Mon, 27 Nov 2006 16:55:02 -0000, Kelley wrote: I would like to be able to round a number based on a decimal value. For example, if the result is 23.7, 23.8, or 23.9, I want the number to round up to 24. I always want to round up for .7 and higher. Is there a way to code this? -- Steve (3) |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Rounding up based on a decimal value
Thanks to both of you for your help. Using Steve's response, I was able to
figure out Jerry's solution yesterday. I also changed the 0.7 to <0.6666 and it works. Thanks again. "Jerry W. Lewis" wrote: I think you meant =IF((A2-INT(A2))<0.7,A2,A2+0.3) which presumes that A20. Also, You need to be a bit more careful about the impact of finite precision binary representations. For instance, if A2 contains 8.7, then ((A2-INT(A2))<0.7 is TRUE. Jerry "SteveW" wrote: That's not what you said the first time :) a2 has value b2 = if((int(a2)-a2)<0.7,a2,a2+0.3) Steve On Mon, 27 Nov 2006 18:16:01 -0000, Kelley wrote: Thanks. If the result is .0, .1, .2, .3, .4, .5, or .6, I need the decimal to stay. If the result is .7, I need it to round up to the nearest integer. It the result is .8, or .9, I need it to round to .1 or .2. "SteveW" wrote: add 0.3, and rounddown 23.6 would be 23.9 - 23 23.7 would be 24.0 - 24 23.8 would be 24.1 - 24 so if values in a2,a3 etc b2=rounddown(a2+0.3) Steve On Mon, 27 Nov 2006 16:55:02 -0000, Kelley wrote: I would like to be able to round a number based on a decimal value. For example, if the result is 23.7, 23.8, or 23.9, I want the number to round up to 24. I always want to round up for .7 and higher. Is there a way to code this? -- Steve (3) |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Rounding up based on a decimal value
Ta for the feedback.
Excel is pretty accurate, but all floating point stuff needs care. If 0.6666 covers the data that you are working with thats the best way. Steve On Tue, 28 Nov 2006 18:54:03 -0000, Kelley wrote: Thanks to both of you for your help. Using Steve's response, I was able to figure out Jerry's solution yesterday. I also changed the 0.7 to <0.6666 and it works. Thanks again. "Jerry W. Lewis" wrote: I think you meant =IF((A2-INT(A2))<0.7,A2,A2+0.3) which presumes that A20. Also, You need to be a bit more careful about the impact of finite precision binary representations. For instance, if A2 contains 8.7, then ((A2-INT(A2))<0.7 is TRUE. Jerry "SteveW" wrote: That's not what you said the first time :) a2 has value b2 = if((int(a2)-a2)<0.7,a2,a2+0.3) Steve On Mon, 27 Nov 2006 18:16:01 -0000, Kelley wrote: Thanks. If the result is .0, .1, .2, .3, .4, .5, or .6, I need the decimal to stay. If the result is .7, I need it to round up to the nearest integer. It the result is .8, or .9, I need it to round to .1 or .2. "SteveW" wrote: add 0.3, and rounddown 23.6 would be 23.9 - 23 23.7 would be 24.0 - 24 23.8 would be 24.1 - 24 so if values in a2,a3 etc b2=rounddown(a2+0.3) Steve On Mon, 27 Nov 2006 16:55:02 -0000, Kelley wrote: I would like to be able to round a number based on a decimal value. For example, if the result is 23.7, 23.8, or 23.9, I want the number to round up to 24. I always want to round up for .7 and higher. Is there a way to code this? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Decimal Rounding | Excel Discussion (Misc queries) | |||
Rounding up for a decimal | Excel Worksheet Functions | |||
Rounding to two even decimal places | Excel Worksheet Functions | |||
Rounding off decimal places | Excel Discussion (Misc queries) | |||
Rounding decimal | Excel Worksheet Functions |