Jump to content
  • 0

Calculating Greatest Common Divisor


Iaron7

Question

4 answers to this question

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:

zlbpG7G.png

Triggered Action:

YfMKYHT.png

The output:

aqrsPWe.png

You may learn more about Triggered Actions in this article if needed https://howto.caspio.com/tables-and-views/triggered-actions/

Hope this helps. And maybe other forum members will have other ideas.  

Link to comment
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
Link to comment
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

 

Link to comment
Share on other sites

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.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

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

Loading...
×
×
  • Create New...