## ProperMod(y, x)

##### Last updated February 24, 2002

**Version:** 1 |
**Requires:** CF5 |
**Library:** MathLib

**Description:**

The mod function is defined as the amount by which a number exceeds the largest integer multiple of the divisor that is not greater than that number. CF has a mod operator, however, it only operates on integers and does not handle situations like 2.3 mod 2 (which should return 0.3).

**Return Values:**

Returns a numeric value.

**Example:**

```
<cfset y = 340>
<cfset x = 60>
<cfoutput>#y# mod #x# is #propermod(y,x)#<br></cfoutput>
<cfset y = -340>
<cfset x = 60>
<cfoutput>#y# mod #x# is #propermod(y,x)#<br></cfoutput>
<cfset y = 2.3>
<cfset x = 2>
<cfoutput>#y# mod #x# is #propermod(y,x)#<br></cfoutput>
```

**Parameters:**

Name | Description | Required |
---|---|---|

y | Number to be modded. | Yes |

x | Devisor. | Yes |

**Full UDF Source: **

```
/**
* Computes the mathematical function Mod(y,x).
*
* @param y Number to be modded.
* @param x Devisor.
* @return Returns a numeric value.
* @author Tom Nunamaker (tom@toshop.com)
* @version 1, February 24, 2002
*/
function ProperMod(y,x) {
var modvalue = y - x * int(y/x);
if (modvalue LT 0) modvalue = modvalue + x;
Return ( modvalue );
}
```

blog comments powered by Disqus
### Search CFLib.org

### Latest Additions

Kevin Cotton added

date2ExcelDate

May 5, 2016

Raymond Camden added

CapFirst

April 25, 2016

Chris Wigginton added

loremIpsum

January 18, 2016

Gary Stanton added

calculateArrival...

November 19, 2015

Sebastiaan Naafs - van Dijk added

getDaysInQuarter

November 13, 2015