5 Replies Latest reply on Sep 4, 2012 11:51 AM by philmodjunk

# Working with negative fractions

### Title

Working with negative fractions

### Post

Hello,

I have a database that uses fractions, always in eighths, that I need to do math on.  I've found a calculation on this form to convert these fractions to decimals so I can do the math, but converting back to a fraction to display afterwords is a little confusing.

If I have a negative fraction with integer, like -1 7/8 (In field fractions) it converts to a decimal fine (Decimal Field) but when I convert back to a fraction from the decimal, i end up with -1 -7/8 (DecimalBackToFraction Field)  I don't want this second "-" before the fraction part, so I created the field Replace that gets rid of it.

This works fine, unless my original fraction doesn't have an integer piece (- 7/8).  it still converts to decimal okay, and back to a fraction fine, but then in the Replace field, it gets rid of the first "-" leaving me with 7/8 which isn't good..

How can I detect if there is an integer or not in the fractions, and display negatives and positives after the math on the decimal values accordingly..?

• ###### 1. Re: Working with negative fractions

I'd use this expression to convert your fraction into a decimal:

Evaluate ( Substitute ( TrimAll ( Fractions ; 1 ; 1 ) ; " " ; If ( Left ( Fractions ; 1 ) = "-" ; "-" ; "+" ) ) )

I'd use this expression to convert the decimal back into eighths:

Let ( [ d = cDecimalValue ;
s = If ( d < 0 ; -1 ; 1 ) ;
i = Abs ( Int ( d ) ) ;
num = (Abs ( d ) - i ) * 8 ] ;
s * i & " " & num & "/8"
)

• ###### 2. Re: Working with negative fractions

Hi,

Thank you for this, It's much cleaner than my solution.

It works great for fractions with integers both negative and positive, however when I work with a negative fraction without an integer, I still get a negative decimal result, which is great, but when i conver that negative decimal back to a fraction, I dont get a negative fraction.

Example: I put -3/8 in "Fractions" it returns -.375 in "Decimal" and in DecimalBacktoFraction i get 0 3/8 when it should be -0 3/8

Here is another sample file.

Any thoughts?

Thanks.

• ###### 3. Re: Working with negative fractions

Let ( [ d = cDecimalValue ;
s = If ( d < 0 ; -1 ; 1 ) ;
i = Abs ( Int ( d ) ) ;
num = (Abs ( d ) - i ) * 8 ] ;
If ( i ; s * i & " " & num & "/8"  ; s*num & "/8" )
)

• ###### 4. Re: Working with negative fractions

Thank You, that works great!

I've now run into another problem related to this..

I've created a sub summary report and want a sub summary displayed in fractions.

I created a summary field that totals up the decimal fields, which are created by the first fraction to decimal calculation you posted.

I then created another field that converts the decimal summary back into a fraction with your second formula.  I've placed both these in a subsummary part in my layout, and the summary decimal field behaves as expected, onyl totaling the sub section, but the fraction field only the total of the entire found set, not the sub sections.

Here is a PDF of my report, showing what I mean. - The decimal on the right is the summary field of the decimal values created from the fractions in the "Pages" Collum.