Format Input to 2 Decimals while Typing HTML/Javascript -


how can create input field currency? i'm looking work follows:

initial:      0.00
type "1": 0.01
type "2": 0.12
type "5": 1.25

i'm pretty new web design, i'm looking simpler solution. saw similar question & answer question angular solution, i'm unsure how implement html project. have simple folder html files in it. thanks!

it tricky do. lack of effort (no code effort shared) in question demotivated me this. complexity invoked me share it. might many other people well.

working demo

document.getelementbyid("demo").onkeydown = function (e) {         //console.log(e.keycode);         if (e.keycode != 37 && e.keycode != 39 && e.keycode != 8 && e.keycode != 46)             e.preventdefault();          if (e.keycode == 8 || e.keycode == 46) {             //if key down (backspaceordel=1) no affect             if (backspaceordel == 1)                 e.preventdefault();             else                 backspaceordel = 1;             return;         }          if (e.keycode < 48 || (e.keycode > 57 && e.keycode <96) || e.keycode > 105 )             return;         try {                             var val = this.value;             var val1 = 0;             if (val == 0) {                 val1 = e.key / 100;             }             else {                 //very tricky. needed val1=val*10+e.key not                  //work correctly floats in javascript.                 //here have different android in logic                 var val1 = parsefloat(val) * 1000;                 val1 += parsefloat(e.key);                 val1 = val1 / 100;             }             val1 = val1.tofixed(2);             if (!isnan(val1))                 this.value = val1;         }         catch (ex) {             alert("invalid amount");         }     }; 

Comments