limit input to 2 decimal places jquery onchange event

133
September 01, 2021, at 11:10 PM

I want when user enter a number into input field like this 54.78987, or any number more than two decimal places, it should automatically go back to two decimal places like 54.78. Function can be use on keyup or onchange event.

Answer 1

use parseFloat.ToFixed(2) for two decimal call.

$(document).ready(function(){
 
  $("#inpt").on('blur',function(){
      var currentObj=$(this);
      var currentVal= currentObj.val();
      if(!isNaN(currentVal)){
        var updatedVal=parseFloat(currentVal).toFixed(2);
        currentObj.val(updatedVal);
      }
      else{
          currentObj.val("");
      }
 })

})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" id="inpt"/>

Rent Charter Buses Company
READ ALSO
Connecting to AxonServer node [192.168.99.100:8124] failed: INTERNAL: Panic! This is a bug

Connecting to AxonServer node [192.168.99.100:8124] failed: INTERNAL: Panic! This is a bug

I use the axon server as a remote server in spring bootnot in the localhost

152
Keyring apparently not installed correctly with pip macos

Keyring apparently not installed correctly with pip macos

I want to use the Python package keyring to avoid exposing passwords in my Python scriptsAccording to what I've read, all you need to do is pip install keyring and then start storing and retrieving credentials

157
Jetpack Compose transparent NavBackStackEntry

Jetpack Compose transparent NavBackStackEntry

When I use Compose Navigation library, even if I set my root view and NavHost to have transparent background color, I see white background

143