1 Reply Latest reply on Sep 17, 2013 9:08 AM by davidanders

# Rounding

Rounding

### Post

Using a formula like this one

Int(Number) + Choose(Int(Mod(Number, 1) /.25), 0, .25, .50,.75)

How would I change it to round to the NEXT 1/8.

example: I need to round

23 1/16 to 23 1/8

23 11/32 to 23 3/8 ....... and so on!

Thanks

• ###### 1. Re: Rounding

•                posted February 27, 2009 by
•
I'd suggest you make this in two steps, otherwise your formula will be utterly unreadable in version 6. The first step is to divide X by Y and round the result to nearest 1/32 (result is Number):

Round ( X / Y * 32, 0 ) / 32
Note that here we have no protection against Y being 0 or empty, which will result in an error.

Let's call the previous result n and move to the second and final step* (result is Text) =

Case ( Int ( n ) ,  Int ( n ) &  " " )
&
Case (
Mod ( n, 1 ),
Mod ( n, 1 ) * 2^( Length (  Mod ( n, 1 ) ) - 1 )
&  "/"  &
2^( Length (  Mod ( n, 1 ) ) - 1 )
)

---
```Fractions to Decimals    By:    John Mark Osborne