Dynamic Decimal Places

How to dynamically change the currency decimal places on SAPUI5

A quick look at handling changing values, e.g. decimal places, and binding them into views.

The Problem

Recently, we come across a very unique requirement. The requirement is as follow:

To display a currency value, with varying precision and scale depending on what is maintained on the database.

On initial investigation, this may look like a pretty straightforward approach of odata model and SAPUI5 data binding. But, upon technical walkthrough, the requirements force us not to maintain the values onย SEGW. This is due to the fact that the precision and scale are dynamic values from another table.

SEGW Properties
SEGW Properties

The Solution

OData Model

For us to maximize the SAPUI5 binding capability, we’ve decided to indicate the precision and scale as properties of the entity type in our service.

In this way, we can still utilize the binding, and fill out the precision and scale dynamically from the tables.

SEGW Properties with Scale and Precision
SEGW Properties with Scale and Precision


Once we’ve converted the precision and scale to a property, we can now use them for binding in our SAPUI5 views. To be more specific, we also utilize the change event on SAPUI5 controller.

Change Event
Change Event


In this approach, we minimize hard coding and additional processing of properties. We also maximize data binding events and all of the UI elements are intact since we still get the values from the context.

This approach is not only limited to use cases such as decimal places but in any field that is dynamic in terms of values.

In making applications, we focus on leveraging the binding events and contexts, since all of this is managed by SAPUI5. Rather than creating own formatters this enables us to maintain data on the backend side, and let the application display or present it without any additional changes.

How about you? How will you tackle this kind of requirements?

Let me know in the comment section below and don’t forget to subscribe for more SAPUI5 content. ๐Ÿ™‚

2 thoughts on “How to dynamically change the currency decimal places on SAPUI5”

Leave a Comment