Want to be a better FileMaker developer? Learn how with the Internet's first school for FileMaker Pro! Head To Grasp Learning


FileMaker How-To: The Truncate Function

In this FileMaker how-to, I will explain how to use FileMaker's Truncate function.

Truncate is a function that shortens any number to a given decimal place. Not to be confused with rounding a number to a given decimal place, Truncate chops off a number at any given decimal place irregardless of the other digits. There is one additional trinket that the Truncate function does, but you'll have to continue reading to find out.

The truncate function accepts two parameters: the number you want to modify and the number of decimal places to leave on the resulting number.

When you first add Truncate to a calculation in FileMaker, it'll be inserted as follows:
Screenshot of the Truncate function FileMaker Calculation Definition

Another way to think of the two values otherwise referred to as parameters in the Truncate function are as follows:

Truncate ( NumberToShorten ; ToWhatDecimalPlace )

So, let's look at some sample output:

Truncate ( 3,456,789.01234 ; 2 ) = 3,456,789.01

Truncate ( 99.99999 ; 3 ) = 99.999

Truncate ( 0.987654321 ; 6 ) = 0.987654

Truncate ( 119,999.99 ; -3 ) = 119,000

That last example might have thrown you for a loop as it doesn't immediately make sense. Where did the 3 x 9s go that preceded the decimal place? Yep, I know what you're thinking, "Just when I thought I got it, you threw that example in there!" This is the other trinket about Truncate's functionality that I was referring to earlier.

Truncate can also erase numbers before a decimal place if you pass a negative number to the precision parameter.

So, really, the better way to think of the parameters in the Truncate function are as follows:

Truncate ( NumberToShorten ; WithWhatPrecision [before or after the decimal place] )

What kind of circumstances call for the Truncate function?

The first that comes to mind is when you need to report the result of a calculation, but don't need every last digit.

For example, when reporting the area of a circle with a radius of 5 feet, is it really important to include 14 decimal places? 5^2 x 3.141592653589793 = 78.53981633974483

While in some cases it may be important to include every last decimal place, there are other cases where using Truncate would be a better option.

Truncate ( 5^2 x 3.141592653589793 ; 4 ) = 78.5398

The easiest way to become familiar with the Truncate function is to open the Data Viewer and experiment with it.
Screenshot of the Truncate function in FileMaker's Data Viewer

So, what are you waiting for, go try it out for yourself!

I've created an example file for the Truncate function, which in the future will only be available to Grasp students. For a limited time only, however, we are offering these files free to our newsletter subscribers. So sign up today using the form to the left.

Please let me know if you found this FileMaker how-to useful. Feel free to send me an email with any thoughts or suggestions that you may have.

What other uses for the Truncate function can you think of?

Let me know in the comments below!

comments powered by Disqus