1

I am using accounting.js (along with bindWithDelay.js) to format a number on keyup or blur. The issue is that when I input in the textbox the second time to modify the number, the plugin formats the number incorrectly the second time.

For example, if I enter the number 28,1, accounting.js formats it this way 28,10. This is the expected output. But when I modify the number the second time to 28.16, accounting.js formats it again to 2.816,00 which is not the intended result.

This is the code:

JS:

accounting.settings = {
        number: {
            precision : 2,  // default precision on numbers is 0
            thousand: ".",
            decimal : ","
        }
    }

        $(".c").bindWithDelay("keyup", function() {
            $(this).val(accounting.formatNumber($(this).val()));
        }, 2000);

HTML:

<input class="c" type="text" id="height" name="height" value=""  />
input
  • 7,503
  • 25
  • 93
  • 150
  • As I see it from their demo page, this is the expected outcome. It just assumes, that you put the `.` in the wrong place and reformats the number to be `2.816` and then appends the decimal places to the end result `2.816,00`. It does not convert the `.` to `,` if it's in the wrong place. If I enter `0.34` it converts the number to `34,00`. – Christoph Mar 12 '17 at 22:58
  • @Christoph, is there anyway I can prevent this behaviour? – input Mar 13 '17 at 17:49
  • I have no idea. I just took a quick look at their documentation. You should try to contact the devs. – Christoph Mar 13 '17 at 18:07

0 Answers0