• 0

# Calculating Greatest Common Divisor

## Question

Any simple way to do this in a calculated field?

## Recommended Posts

• 0

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

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
##### Share on other sites

• 0

Hello - if you want to use ROUNDDOWN and ROUNDUP like from Excel, you can use these formulas:

Excel:

Round to last nearest 5 = ROUNDDOWN(A2/5,0)*5
Round to last nearest 10 = ROUNDDOWN(A2/10,0)*10
Round to last nearest 50 = ROUNDDOWN(A2/50,0)*50
Round to last nearest 100 = ROUNDDOWN(A2/100,0)*100

Caspio:

`FLOOR([@field:Number]/50)*50`

Excel:

Round to next nearest 5 = ROUNDUP(A2/5,0)*5
Round to next nearest 10 = ROUNDUP(A2/10,0)*10
Round to next nearest 50 = ROUNDUP(A2/50,0)*50
Round to next nearest 100 = ROUNDUP(A2/100,0)*100

Caspio:

`CEILING([@field:Number]/5)*5`

##### Share on other sites

• 0

Just want to add, you may check the function reference in Caspio's howto page for some possible formulas that you can use:

## 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.