Showing results for 
Search instead for 
Did you mean: 

How to round a number with a data type float?


Hello all,

I got a float type value of "Amount" field in database 8,124.12 and when display this value in UI5, I got the value of 8,124.11

This is my UI5 code:

value="{path: 'AMOUNT', type: 'sap.ui.model.type.Float', formatOptions: {maxFractionDigits: 2, roundingMode: 'AWAY_FROM_ZERO', parseAsString: true, style: 'standard'}}"
valueLiveUpdate="false" maxLength="50" name="AMOUNT"/>

Amount data type definition:

{name = "AMOUNT"; sqlType = DOUBLE; comment = "Amount";},

And the value from OData:

How can I get the correct value in UI5 as in database record (which is 8,124.12 and not 8,124.11) ?



View Entire Topic
Product and Topic Expert
Product and Topic Expert
0 Kudos

If the entity property "AMOUNT" has a type of "Edm.Double" (check the $metadata document), the binding type 'sap.ui.model.odata.type.Double' has to be assigned in place of Float.

  path: 'AMOUNT',
  type: 'sap.ui.model.odata.type.Double',
  formatOptions: {
    maxFractionDigits: 2,
    roundingMode: 'AWAY_FROM_ZERO'

Keep in mind that the value of "roundingMode" needs to be in lower case if the target SAPUI5 version is lower than 1.85.* I.e. 'AWAY_FROM_ZERO' → 'away_from_zero'.


* Related issue:
See also


Thank you boghyon.hoffmann ! It worked as expected.

0 Kudos

Hello boghyon.hoffmann,

For JSON Model also we can do the same process? or is there any alternative can you please help me with this.

Thanks in advance.

Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi there,

You have a question and need help by the community? Instead of posting into an old question thread, it is more helpful for you, if you create your own question. Here is how to get started:

  1. Learn about asking and answering questions in SAP Community with this tutorial:
  2. Ask your detailed question here:
  3. Wait for a response.

That's it. Thank you!

Best regards

Your SAP Community moderator

Product and Topic Expert
Product and Topic Expert
0 Kudos

sshanmuka Does this help? -->,preview:?sap-ui-xx-componentPreload=...

With a client side model (e.g. JSONModel), 'sap.ui.model.type.Float' can be used, instead of 'sap.ui.model.odata.type.Double'.