Code

Round numbers decimals or integers

An easy way to round numbers, decimals, or integers based on your requirements in Webflow via a Javascript snippet. You can round numbers to the nearest whole integer or nearest thousand

Round numbers decimals or integers preview

An easy way to round numbers, decimals, or integers based on your requirements in Webflow via a Javascript snippet. You can round numbers to the nearest whole integer or nearest thousand

How to add it

  1. Add the necessary Javascript snippet to the closing body tag of your Webflow page settings.

The code

Javascript
                      // Round to nearest whole integer
<script>
var theNumber = 18510.01;
var roundedNumber = Math.round(theNumber); // will output 18500
</script>

// Round to nearest thousand
<script>
var theNumber = 18510.01;
var roundedNumber = Math.round(theNumber/1000)*1000; //will output 19000
</script>

                    

Browse similar code snippets

Language

More from Corey Moen

Profile →

Similar code snippets

All code snippets →