What would be the best way to do the following in Javascript / AngularJS?
I have an input box and a soft numeric 10 key (buttons).
Instead of having the user enter "." on the keyboard or press the "." on the soft pad, the input should assume a number 2 places or less is a decimal
User Enters:
1 = 0.01
2 = 0.12
3 = 1.23
.00 = 123.00
It needs to be able to handle mixing keyboard and soft key input. The user can press the "." key on the physical numpad. The soft numpad only has 0 and .00, no "." key.
The backspace key would delete 1 digit from the right. 100.50 then clicking backspace should produce 10.50, not 100.5
The advantage to the "fixed decimal" is not needing to enter a ".", which would be far more common than entering whole numbers outside of the quick cash buttons I have on the right.
Currency formatting the value in the inputbox is a requirement, but outside of the scope of this particular question. (thinking of using ng-currency or numbrojs (since ng-currency stores the model as a float)).
I'm currently working through the problem:
function concatNumber(num)
{
if (vm.transaction.paymentAmount === undefined || vm.transaction.paymentAmount === 0 || vm.transaction.paymentAmount === '')
{
vm.transaction.paymentAmount = '0.0' + num;
return;
}
}