That's more or less basic HTML/JavaScript code, with the exception of the clamp() function which is a (trivial) SugarCube addition to Number.prototype. If you want literally just the "A.BC" format, it's best to use a text input field with a validity pattern and some validation:
<input id="myValText" type="text" pattern="\d\.\d\d"
onchange="if(!this.checkValidity()) {
this.value = (Math.round((Number(this.value) || 0) * 100).clamp(0, 999) / 100).toFixed(2);
}"/>
You can then poll the (text!) value with document.getElementById("myValText").value - if you prefer it to be numeric, use Number(document.getElementById("myValText").value).
An alternative is to use a numbered text input, but it still would allow "invalid" text input, so the way to fix it is roughly the same. On the upside, you now have different (potentially more optimised) input methods, especially on mobile devices.
<input id="myValNumber" type="number" step="0.01" min="0" max="9.99"
onchange="if(!this.checkValidity()) {
this.value = Math.round((Number(this.value) || 0) * 100).clamp(0, 999) / 100;
}"/>
You get to the number the same way, for example via document.getElementById("myValNumber").value or Number(document.getElementById("myValNumber").value), depending on if you want to have a string or number in the end.
If you want to have the current values of some variables (in the following examples $muh and $meh) to be automatically filled in and updated (though the updates won't "stick" until a passage change, as usual with SugarCube), the following example shows both at once.
<input id="myValText" type="text" pattern="\d\.\d\d"
onchange="if(!this.checkValidity()) {
this.value = (Math.round((Number(this.value) || 0) * 100).clamp(0, 999) / 100).toFixed(2);
}
SugarCube.State.setVar('$muh', Number(this.value));"/>
<input id="myValNumber" type="number" step="0.01" min="0" max="9.99"
onchange="if(!this.checkValidity()) {
this.value = Math.round((Number(this.value) || 0) * 100).clamp(0, 999) / 100;
}
SugarCube.State.setVar('$meh', Number(this.value));"/>
<<script>>
jQuery(function() {
document.getElementById("myValText").value = (Number(variables().muh) || 0).toFixed(2);
document.getElementById("myValNumber").value = Number(variables().meh) || 0;
});
<</script>>