Rounding with decimals | Community
Skip to main content
ChrisBudgen
Level 5
February 6, 2022
Solved

Rounding with decimals

  • February 6, 2022
  • 2 replies
  • 1126 views

I can't find a way to round a number to a specific number of decimals. So e.g. 3.14159 to 3.1416 or 3.14

I'm surely missing something. Any ideas where to find that function?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by AndyHess

Hi Chris,

We use round, but have to extend the number past the decimal range first because our round() feature only rounds to the nearest integer.

Using this method on 3.14159 i get

The formulas to handle this look like this:

So, again , you round the number multiplied by the factor of the digits you want then divide the newly rounded integer by the same factor

2 replies

jrieth
Level 3
February 7, 2022

formatNumber under math functions. ~Jeff

ChrisBudgen
Level 5
February 7, 2022

Hi @Jeff Rieth‚ thanks for the answer. I tried that but it just cuts off at the defined decimal number, it doesn't round :-(

AndyHess
Adobe Employee
AndyHessAdobe EmployeeAccepted solution
Adobe Employee
February 7, 2022

Hi Chris,

We use round, but have to extend the number past the decimal range first because our round() feature only rounds to the nearest integer.

Using this method on 3.14159 i get

The formulas to handle this look like this:

So, again , you round the number multiplied by the factor of the digits you want then divide the newly rounded integer by the same factor

ChrisBudgen
Level 5
February 7, 2022

@Andy Hess‚ thanks for the solution! Perhaps it makes sense that this finds its way into the documentation?