customd / jquery-number

Easily format numbers for display use. Replace numbers inline in a document, or return a formatted number for other uses.
https://www.customd.com/articles/14/jquery-number-format-redux
MIT License
442 stars 402 forks source link

Problem entering decimal numbers < 1 #126

Open RichardDavies opened 7 years ago

RichardDavies commented 7 years ago

With the as-you-type formatting on an input that allows decimal numbers such as $('#price').number( true, 2 ); it behaves very oddly when entering numbers less than 1 such as 0.50, 0.25, or 0.01 etc.

This weird behavior is easily reproduced using your as-you-type demo with Chrome, Firefox, or IE.

AnggonoHanggi commented 7 years ago

i also got strange behaviour when i want to show data with decimal number for example 100000000.0000 then i do $('.number').number(true, 4, ' , ', ' ');

it becomes 1 000 000 000 000,0000

FrenchMajesty commented 7 years ago

Dealing with the same problem. Has anyone found a solution to this?

timothyfarmer commented 6 years ago

I'm having these same issues and its causing me some grief. I'm guessing I just need to dive deep into this plugin and try to fix it.

josexp3 commented 6 years ago

You need to change the condition after this line: // The whole lot has been selected, or if the field is empty, and the character Instead of this if (start == 0 && end == this.value.length || $this.val() == 0) use this one if (start == 0 && end == this.value.length)

The or condition seems to be the problem