Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7545087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:50:19+00:00 2026-05-30T08:50:19+00:00

I am developing a web site in which i want the number to be

  • 0

I am developing a web site in which i want the number to be formatted in the given requirement that is as below:

  • If I press “1” it should say “1”.
  • If I press “12” it should say “12”.
  • If I press “123” it should say “1.23”.
  • If I press “1234” it should say “12.34”.
  • This sequence should also work when I press backspace.

I have developed it on my own that is as below:

        function Maskme(obj, evt) {

        var event = (window.event) ? window.event : evt;

        var str = document.getElementById("txtamt");
        if (event.keyCode != 8 && event.keyCode != 13) {

            if (str.value.length == 3 && str.value.indexOf(".") == -1) {
                var val = parseFloat(str.value);
                var val1 = (val / 100).toFixed(2);
                str.value = val1;
            }
            else if (str.value.length > 3) {
                var val = parseFloat(str.value) * 1000;
                var val1 = (val / 100).toFixed(2);
                str.value = val1;
            }
            else {
                str.value = str.value;
            }
        }
        else {
            if (event.keyCode != 13) {
                var str1 = parseFloat(str.value) / 10;
                if (str1 != 0 && !isNaN(str1))
                    str.value = (str1).toFixed(2);
                else
                    str.value = "";
            }
        }
    }

But I am having problem that is:

  1. If I rapidly press “123” it says “12.30” or “12.3” instead of “1.23”
  2. Backspace is also not working after I reach back to 1.23
  3. maximum 7 digits are allowed to enter in the text field

If there any ready made plugin available or anyone has already developed this kind of plugin then please inform me I will appreciate it a lot.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T08:50:21+00:00Added an answer on May 30, 2026 at 8:50 am

    I changed it to replace the dot first and then the calculate is pretty easy:

    $("#txtamt").keyup(function(obj, evt) {
        var event = (window.event) ? window.event : evt;
    
        //ignore arrow keys so that user can move curser 
        switch(event.keyCode)
        {
            case 37:
            case 38:
            case 39:
            case 40:
                return;
            default:
                break;
        }                
    
        var str = document.getElementById("txtamt");
        str.value = str.value.replace(".", "");
    
        if (str.value.length == 3) {
            var val = parseFloat(str.value);
            var val1 = (val / 10).toFixed(1);
            str.value = val1;
        }
        else if (str.value.length > 3) {
            var val = parseFloat(str.value);
            var val1 = (val / 100).toFixed(2);
            str.value = val1;
        }        
    });
    

    ​

    DEMO: http://jsfiddle.net/ceJcn/7/
    ​

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a JSON/REST web API, for which I specifically want third party
I am beginner in web development, I am developing a site that allows user
I'm new to the asp.net. I'm developing one web site which is having diffenent
I'm developing an Android app that fetches a web page from a website which
Hi I am developing app which downloads the images from the web site and
I am developing a web site and need to see how it will look
I'm developing a web site containing 3 pages (Home, page2, page3) ... in the
I am using ASP.NET MVC for developing a web site. I am using jquery
In general, If I have a choice when developing a web site to use
I am developing an international web site - multiple countries, multiple languages. I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.