Number Per Word - jquery

Does anyone know a way to describe a monetary value or a plugin that does this?

exp: if I have $ 1,200,000.00 and user hover()value: description will be " one million two hundred "

Thank!

+5
source share
5 answers

The following page mentions a very simple implementation:

Number for words | Javascript

which can perform the conversion using this function:

var words = toWords(num);

Using jQuery, you can wrap this inside your hover function, as shown below:

//This will add a tooltip upon hovering with the "word" value.
$('div').hover(function(){
    $(this).attr('title',toWords($(this).text()));
});

Working demo

+12
source

Here is a Javascript solution that is compact and works well:

Number for words

It can be used as follows:

var words = toWords(num);
+1
source

Validation for a text field that allows only one dot

if(!document.getElementById("per").value.match(/^[0-9]*\.?[0-9]*$/)) //"per" is the id text box
{
   alert("Enter Correct Interest Rate");
   return (false);
}

Hope this helps.

0
source
you can add this code for number to word.if your field are coming dynamic.Just apply the class ".numtowordcls" on your input type

function getNumberToWord(thisObj){
        var dataType=$(thisObj).attr("dir");

         if(dataType!=null && dataType!="" ){
            var value=$(thisObj).val();
            if(dataType==='decimal' || dataType==='currency' || dataType==='number' || dataType==='emd' ){
                if(value!=undefined && value.trim()!="" ){
                    if(isNaN(value)){
                    alert("Kindly Enter Valid Value For Filed Type '"+dataType+"'");
                    $(thisObj).val("");
                    $(thisObj).focus();
                    }else{
                        if(value!=undefined && value.trim()!=""){
                            if(!$.isNumeric(value)){
                            alert("Please Eneter Numeric value !!!");
                            $(this).val('');
                            return false;
                            }

                            var firstPart=value.toString().split(".")[0];
                            if(firstPart.length>14){
                                alert("Please Enter value upto 14 Digit !!!");
                                $(thisObj).val(value.substr(0,14));
                                $(thisObj).focus();
                                return false;
                            }
                            var secondPart=value.toString().split(".")[1];
                            if(secondPart!=undefined && secondPart!="" && secondPart.length>2){
                                alert("Decimal allowed upto 2 places !!!");
                                $(thisObj).val(value.substr(0,14));
                                $(thisObj).focus();
                                return false;
                            }  
                        }
                    }
                }

            }

        } 
        $(".numtowordcls").each(function(){
            var id=$(this).attr("id");
            var dirObj=$(this).attr("dir");
            var dataArray=id.split("_");
            var finalId=dataArray[0]+"_"+dataArray[1]+"_"+dirObj;
            var fieldvalue=$("#"+finalId).val();
            if(fieldvalue!=undefined && fieldvalue.trim()!=""){
                var ntwidvalue=ntwidvalue+""+$(this).attr("id")+"~~~"+parseFloat(fieldvalue)+"~~~~";

            }else{
                $('#'+id).val("");
            }

        });
        console.log("aaaa");
        $('button').click(function(){
            var input = $('input');
            input.val('ntwidvalue');
            input.trigger('input');
        });
    }
0
source

All Articles