Do you want more options to round numbers in Gravity Forms Number Fields and calculations? And decide in which direction to round the number, like rounding up (ceil), rounding down (floor) or automatically (round up or down dependend on the value you want to round)? With the GravityWP – Advanced Number Field that’s as easy as it gets.
Rounding up to 5 decimal places
With Advanced Number Field enabled, you can easily select a checkbox in your Field Settings of the Gravity Forms Number Field you want to round. Two extra options appear:
- Rounding to decimal places: you can select up to 5 decimal places to round.
- Rounding method: Round (up or down depending on the value), Ceil (rounding up), Floor (rounding down)
Using rounding on calculations
You can also activate rounding on calculations. Make a calculations like you are used to, using Merge Tags with number values and select ‘Round the Value’ to automatically round the outcome of the calculation.
Use in combination with custom units
You can use the rounding option in combination with custom units like square or cubic meters (m2, m3), the percentage sign (%), degrees Celcius or Fahrenheid (°C, °F), Irradiance (W/m2) or another custom unit.
Check out the Tutorial about Custom Units for Gravity Forms Number Fields.
Rounding without add-on
You can read on the Gravity Forms community forum more about rounding without an add-on. This is no standard functionality in Gravity Forms for rounding, but with custom JavaScript/jQuery you can program your own solution if you want the rounding to happen in real time.
If real-time rounding is not necessary, you can also use the gform_field_validation filter to check the entered value or the gform_pre_submission filter to change the value after submission. Read more on the Gravity Forms forum.
Rounding by Increments GravityWiz
Gravity Perks has a snippet available to round numbers by increment using specific CSS classes. You can add the snippet to your functions.php file or download it as a plugin from their website. This can be also very handy if you want rounding on bigger numbers, like rounding to 100 if something is above 50.