turf.round
What is turf.round?
turf.round is a small math helper that rounds a number to a given decimal precision. Unlike Math.round (which only rounds to integers), turf.round accepts a precision argument so you can round to any number of decimal places.
turf.round(num, precision?) → numberArguments:
num— the number to roundprecision— number of decimal places (default0)
When would you use turf.round?
Use turf.round when formatting numeric output from other Turf calls — for example, displaying a computed turf.area to two decimal places or a turf.distance rounded to the nearest metre. It is not a geometry function but shows up in many UI-facing pipelines alongside real Turf operations.
For trimming coordinate precision on GeoJSON features before saving or transmitting, use turf.truncate instead — it walks coordinates and applies precision globally. turf.round is scalar-only.
undefinedFAQs
How is turf.round different from Math.round?
Math.round only rounds to integers. turf.round(123.4567, 2) returns 123.46. It is functionally equivalent to Math.round(n * 10^p) / 10^p, but packaged for consistent use with other Turf helpers.
Should I use this to trim coordinate precision?
No — use turf.truncate for features. turf.round operates on a single number at a time. truncate walks all coordinates of a Feature or FeatureCollection and trims their precision in one call.
Where does it live in the package structure?
It is exported from @turf/helpers in current versions of Turf and re-exported from the top-level @turf/turf bundle. If you only need rounding, a native Math.round equivalent is usually sufficient.
Does it handle negative precision?
Yes — turf.round(1234, -2) returns 1200, rounding to the nearest hundred. Useful for binning approximate values in analytics.