Skip to Content
author's profile photo Former Member
Former Member

binding type with decimal

Hi Guru's,

I am having issues with validating input fields, hopefully someone can explain to me what is going wrong because clearly I am doing something wrong 🤣.

I have table in the Hana database which allows to enter materials, some of the fields contain weights and these must be entered in whole or decimal values with a maximum of two decimals. so in my hdbdd file I have an entry like this: "NET_DECL_WEIGHT: numbericDecimal;". This numbericDecimal type is defined as an decimal (type numbericDecimal: Decimal(8,2);).

So enough about the table definition, in my controller file I attached the validation handlers as follows:

// Attaching validation handlers

sap.ui.getCore().attachValidationError(function (oEvent) {
















And in my XML view I created an input field as follows:

<Input value="{



formatOptions: {

minIntegerDigits: 1,

minFractionDigits: 2,

maxFractionDigits: 2,

decimals: 2,

decimalSeparator: '.',

roundingMode: 'HALF_CEILING',

groupingEnabled: false


}" textAlign="Right" placeholder="{i18n>assignmentPlaceholderWeight}" description="{i18n>assignmentMaterialWeightDesc}" />

The problem is however that the "attachValidationError" event is raised as soon as I type an decimal value in the input field. A comma is seen as a separator and a dot as a decimal. so when I type "1234,5678" then the "attachValidationSuccess" event is raised and the data is converted into "12345678.00". But when I type "1234.5678" the "attachValidationError" event is raised.

Previously I tried the type "sap.ui.model.type.Float" and that one works fine, however, I couldn't save the data back into the database which is caused (I assume) by the fact that the datafield in Hana is a Decimal and I Could not find a way to define it as a Float value.

I don't know if you need any more information, if so please let me know. I am still quiet new with these binding techniques but love to learn how to do this in a correct way since in the past I wrote seperate "onChange" functions for this which I like to avoid if possible.

Kind Regards,


Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jun 23, 2016 at 01:18 PM


    Please take a look on this on how to use the Odata Types : OData Types - User Interface Add-On for SAP NetWeaver - SAP Library

    Might be adding constraints solves your problem.



    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Viplove,

      I continued to struggle and found out that under the constraints area in the API guide SAP mentions the following:

      {int|string} oConstraints.precision?, Default: Infinity the maximum number of digits allowed in the property’s value {int|string} oConstraints.scale? the maximum number of digits allowed to the right of the decimal point; the number must be less than precision (if given). As a special case, "variable" is supported.

      The number of digits to the right of the decimal point may vary from zero to scale, and the number of digits to the left of the decimal point may vary from one to precision minus scale.

      The number is always displayed with exactly scale digits to the right of the decimal point (unless scale is "variable").

      Although the question marks (as far as I know) mean that they are optional I did find the message saying that the scale should be less then the precision interesting since the precision has a default value while the scale does not.

      So I tried to add the scale constraint to e.g. 50 (since the formatting already takes care of reducing the amount of decimals) and all of a sudden it works :-). So thanks for your answer because although it didn't immediately solve my issue it put me in the right direction..I still wonder though if this isn't simply a bug because I still do not understand why I should use a scale constraint if I don't even want one.

      Kind Regards,

      Nico van der Linden

  • Posted on Jun 22, 2016 at 04:28 PM

    What's issue? what u want to achieve?

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Jun Wu,

      I want these fields to check that only numeric values are added and when more then 2 decimals are entered it should round the second decimal up or down. I don't know how sapui5 handles locales because the app will be used in different countries of which some use 'comma's' and some use 'dots' as a decimal notation.

      But my main issue at the moment is that an error in the validation is raised as soon as I enter a decimal value which I don't understand since the type is an odata Decimal type?

      actually, what I noticed is that I can write any number ending on .00 and is gives a 'success' message e.g. 1234.00 validates successfull. But when I increase the decimal e.g. to 1234.01 then it gives an validation error... And I have no idea why?

  • author's profile photo Former Member
    Former Member
    Posted on Jun 23, 2016 at 12:40 PM

    Ok I think my original question was not entirely clear, so let me try to rephrase it.

    I have a database field which is of type edm.Decimal(8,2), I don't see an option to use Float on Hana so therefore this Decimal type was used.

    In sapui5 I use binding to my form, for the decimal fields I want to format them and only allow the correct decimal input. When I only use <Input value="{ path: 'NET_DECL_WEIGHT' }" /> for the decimal field then it goes fine but it does not save the decimal value. I tried using "type: 'sap.ui.model.type.Float'" then I can use the formatters but as soon as I save the data I get the error:

    The serialized resource has an invalid value in member 'NET_DECL_WEIGHT'."

    This error is caused (I assume) due to the fact that edm.decimal is not compatible with the sap.ui.model.type.Float type. So I looked around and found that you could use the sap.ui.model.odata.type.Decimal type. But when I use that I get the following issue:

    - typing decimals in this input field (e.g. 2.1212) will always generate a validation error (although strangely enough 2.00 works fine...)

    So my question is how can I use a decimal input field with validation on the binding and save it back into the database as as edm.Decimal type..

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.