From Learn @ Cemetech
Jump to navigationJump to search


Command Summary

Returns the fractional part of a value.

Command Syntax


Menu Location


  1. MATH to access the Math menu.
  2. RIGHT to access the NUM submenu.
  3. 4 to select fPart(, or use arrows.

Calculator Compatibility


Token Size

1 byte

fPart(value) returns the fractional part of value. Also works on complex numbers, lists and matrices.


Advanced Uses

fPart(, along with Int( or IPart(, can be used for integer Compression.

Also, fPart( is an easy way to find A mod B (the positive remainder when A is divided by B).


If A is guaranteed to be positive, the following shorter code can be used, omitting B(A<0):


Finally, the easiest way to check if a number is a whole number is not(fPart(X:

:If not(fPart(X:Then
: // X is an integer
: // X is not an integer

You can use this, for example, to check if a number is divisible by another: if X is divisible by N, then X/N is a whole number. This is useful when you want to find the factors of a number. Warning: when storing values with repeating decimals and later multiplying them to see if a number makes it an integer it can return a value of 1 or -1 instead of 0 even if it is an integer. Example: if you store 1/3 as X and then do fpart(3x) it will return 1 instead of 0. This is because fpart(.999...) results in .999... and then rounds to 1 when displaying rather than rounding to 1.0 and then displaying the fpart( as 0.


Often you want to find the value of a-1 mod b -- this occurs, for example, in movement routines with wraparound. However, the problem is that if a=0, a-1 will be negative. Rather than use the longer version of the modulo routine, you might replace subtracting 1 with adding (b-1). This will have the same result, but without sign problems.

Related Commands

See Also