Set number of decimal places?

Is there a built-in way to set the number of decimal places of numbers when displayed (e.g. Text component)? The ‘create text with’ logic block is the only way I see to explicitly convert, but no way to set the display precision.

The 15 decimal places of lat and lng are getting ‘painful’!

A simple solution is to use a little JS to process the number.

Add logic for the Content Logic handler of your Text component. Here’s mine:

The Custom Code block does the following:
UI Builder - ConsoleDemo - Backendless 2022-09-09 16-54-14

Here’s the same code from the screenshot above:

return Number.parseFloat(value).toFixed(2);

Finally, a demo page:

Hope this helps.


Thanks Mark, that works; adding a ‘precision’ argument allows setting the number of decimal places.

The ‘SetPrecision’ custom function I implemented is not nearly as elegant. Seems the takeaway here is to spend a little time looking for a JavaScript solution … a useful learning tool for a JS newbie.

Mark, where do I find the custom code block I built? I don’t see it in a list anywhere (like you do with custom functions).

I can copy the custom code block to a new event on the same page, but can’t copy to another page. What am I missing?

Custom code block will be in the logic where you built it. It will not appear in any lists.

Makes the scope pretty limited. However, seems the custom code block can be ‘wrapped’ in a custom function, giving container scope.

Any problems with this workaround?

That’s the way to go when you add code/logic meant for reuse.