How Do I Round 1.56666666666 to "1.6"?

Trying to sort out:

How Do I Round 1.56666666666 to “1.6” ?

Thanks!!

2 Likes

If you are just talking about display purposes, then :formatted will perform rounding

2 Likes

Not for display purposes because doing this will save it as a Text.

I need it rounded and preserved as a Number type.

Okay, if not display, then what? Storing in the database? Pre-filling an input? Something else?

Yes storing it into the database as a rounded number.

Assuming that value is coming from a user input, then I would turn to the Expression element from @mishav’s Toolbox plugin, and then reference that value in your database action. In the expression you can use the javascript method .toFixed like so:

39%20AM

1 Like

Unfortunately it’s not from a user input but run on an API workflow after calculating the distance between two points.

Sometimes it comes out like 1.5666666666 and i’m trying to get it to round to 1.6 miles and save this number in the database as a Number.

Hi Justin,

You can also just use the formula which Bubble offers instead of a plugin. This is what Bubble reference says about it:
:rounded to

Rounds the first number so that it has X digits after the decimal. For example, ‘0.234’ becomes ‘0.23’ with an argument of ‘2,’ and ‘0.5’ becomes ‘1’ with an argument of '0.

------------End of Reference Bubble

So In an example the formula for saving 1.6666666 as 1.6 in the database the formula is:
(Create a new “product”)
Price=Input price icecream’s value: rounded to 1

9 Likes

Just missed you answer above.
Same thing though.
The formula you use to calculate the distance between the two points you end with ‘rounded to…’

For instance, in my app I calculate a percentage per week. If I would want it rounded it would look like this:

Hope it helps

3 Likes

Oh good grief… I’m so use to doing calculations in expressions I skipped right over thinking this could be done natively! Too funny.

1 Like

And there it is. After half a year of Bubbling I have just achieved my first ’ Solution’. So proud right now, sooo proud.

9 Likes

It’s a good thing you are here, else I’d be having Justin write a custom routine to add two numbers! :joy: I’m blaming tryptophan! :turkey:

3 Likes

This topic was automatically closed after 70 days. New replies are no longer allowed.