• 0

# Calculating Greatest Common Divisor

Go to solution Solved by CoopperBackpack,

## Question

Any simple way to do this in a calculated field?

## Recommended Posts

• 0
• Solution

Hello @Iaron7,

I am afraid that that there is no ready function in SQL to calculate the greatest common divisor. The solution requires using the loop.

So, it looks like this is not possible to calculate the GCD in the Calculated Field. You may find supported function in this article https://howto.caspio.com/function-reference/

As an option, it is possible to make this calculation by the Triggered Actions.

The example of the table design: Triggered Action: The output: Hope this helps. And maybe other forum members will have other ideas.

##### Share on other sites
• 0
Posted (edited)

Thanks for the answer, it does look like using the Triggered Actions loop is the way to get the proper GCD.

Im using a little quick and dirty solution for now. Since I wanted this to calculate on the fly, i had to use conditionals within the calcluated field.

So if a ratio is 31/130, i divide the divisor by the dividend (130 / 31) and get 4.19 or 1 / 4.19.

Now based on what the rounded tenths place of the quotient is, i either:

.1 = round down

.2 or .5 = multiply dividend and divisor by 5 or 2 respectfully.

.3 = multiply by 3 and round up

.4 = multiply by 2 and round up

.6 = multiply by 2 and round down

.7 = multiply by 3 and round down

.8 = round up

.9 = round up.

This gets me to a reasonable ratio for the purposes of my report.

Figured i'd share in case anyone else stumbled upon this and may find it useful for their case.

Edited by Iaron7
misspellings

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible. ×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.