Decimal number resets to 0 after precision is more than 2 precision

Posted by: nilesh_nichal on 2 August 2024, 2:55 pm EST

  • Posted 2 August 2024, 2:55 pm EST

    Hi Team,

    Decimal number resets to 0 after precision is more than 2 precision, For example: 45.67654 will look like 45.00000 or 754.89765 as 754.00000,

    we are using below code

    public override set value(value: number) {
        if (value != this._value) {
          try {
            value = wjcCore.asNumber(
              value,
              !this.isRequired || (value == null && this._value == null)
            );
          } catch (e) {}
    
          value = _.toNumber(value);
          value = _.isNaN(value) ? 0 : value;
    
          if (value == null) {
            this._setText('');
          } else if (!isNaN(value)) {
            let text = wjcCore.Globalize.format(value, this.format);
            this._setText(text);
          }
        }
      }

    Please resolve the issue.

  • Posted 6 August 2024, 1:02 am EST

    Hi Nilesh,

    We tried to replicate the issue based on the code provided but we were not able to replicate the issue on our end. Here is the sample in which we tried to replicate the issue - https://stackblitz.com/edit/angular-xyafuw?file=src%2Fapp%2Fapp.component.ts

    Can you please update this sample to replicate the issue and share it with us, so that we can investigate the issue further and assist you accordingly?

    Thanks, and regards

  • Posted 6 August 2024, 1:41 am EST

    Hi Vivek,

    In the above sample, I want to perform precision value to be added when we click it outside and not when we are adding the decimal or dot, for eg in the link -https://stackblitz.com/edit/angular-xyafuw?file=src%2Fapp%2Fapp.component.ts, here you can see when we type 2 then it will remain 2 untill unless we are giving dot (.) at the end of 2, then it will become 2.00

    I want to have this functionality when we click outside the input box then 2 will become 2.00

    please let me know the solution for it.

  • Posted 7 August 2024, 5:09 am EST

    Hi Nilesh,

    In that case, you can handle the ‘input’ event on the inputElement of the InputNumber control and use the ‘stopImmediatePropagation’ method to stop the default handlers of this event. All the updation will occur on focus out after this implementation.

    Please refer to the following updated sample for the same - https://stackblitz.com/edit/angular-tnc9qx?file=src%2Fapp%2Fapp.component.ts

    Please note that, we have set the ‘format’ property of the InputNumber control to ‘n2’, it allows the user to enter decimal values up to two decimal places only, you can set the format as per your needs, like ‘n5’ or ‘n7’. You can also refer to the following API link for more information about this property - https://developer.mescius.com/wijmo/api/classes/wijmo_input.inputnumber.html#format

    Regards

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels