Skip to main content
Ben Nadel at cf.Objective() 2009 (Minneapolis, MN) with: Steve Withington
Ben Nadel at cf.Objective() 2009 (Minneapolis, MN) with: Steve Withington

New round() Precision In Adobe ColdFusion 2025 Update 8

By
Published in

This is a super minor improvement in the recent releases of Adobe ColdFusion 2025, but the need has come up in my code enough to merit a quick mention. The round() function now accepts a number of decimal places for rounding precision. Historically, the round() function has only rounded to the nearest integer. Which meant that if you wanted to round to, for example, 2 decimal places, you had to jump through some hoops to get there. But now, you can just pass a second argument with the number of decimals places desired.

Here's a quick demo:

<cfscript>

	value = 123.45678;

	writeDump([
		"Original Value": value,

		// OLD: Using number format.
		"Number Format": numberFormat( value, ",0.000" ),

		// OLD: Using decimal shifting.
		"Decimal Shifting": ( round( value * 1000 ) / 1000 ),

		// NEW: Using new round precision.
		"Round Precision": round( value, 3 ),
	]);

</cfscript>

In the call to round(), I'm passing in 3, which will round the decimal value to the 3rd decimal point:

Screenshot of CFDump showing rounding result using various methods - all outcomes are the same (visually).

One thing to note is that only the numberFormat() approach will include the commas if the integer portion is larger than 1,000. The round() approach simply truncates the decimal portion to the given number of decimal places; but it doesn't apply any other formatting.

Epilogue On Significant Digits

Having nothing to do with the round() function itself, one thing worth noting is that when doing maths, you sometimes have to contend with "significant digits". I'm a little rusty here — I first learned about significant digits in my middle school "Natural Science" class; but the idea is that the outcome of your calculations needs to be limited by the input with the least number of significant digits.

As a simple example, imagine that we're calculating the area of a piece of wood:

  • Width: 8.3 inches
  • Length: 6.5 inches

In this set of measurements, both numbers have 2 significant digits. Which means that while the calculator math works out to be 53.95 (4 significant digits), the outcome that we can most confidently report is really 54. If we left in the .95 decimal place significant digits, we would merely be pretending that we had such precise confidence!

Yay for science!

Want to use code from this post? Check out the license.

Reader Comments

Post A Comment — I'd Love To Hear From You!

Post a Comment

I believe in love. I believe in compassion. I believe in human rights. I believe that we can afford to give more of these gifts to the world around us because it costs us nothing to be decent and kind and understanding. And, I want you to know that when you land on this site, you are accepted for who you are, no matter how you identify, what truths you live, or whatever kind of goofy shit makes you feel alive! Rock on with your bad self!
Ben Nadel
Managed ColdFusion hosting services provided by:
xByte Cloud Logo