Number to Word - jquery

后端 未结 5 1162
忘了有多久
忘了有多久 2020-12-06 07:35

Anyone know\'s a way to describe a cash value or a plugin who does that ?

exp: if i have $ 1.200.000,00 and the user hover() the value:

相关标签:
5条回答
  • 2020-12-06 07:59

    Validation for text box allowing 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);
    }
    

    I hope this might help.

    0 讨论(0)
  • 2020-12-06 08:02

    The following page mentions a very simple implementation:

    Number to Words | Javascript

    which can perform the conversion by using this function:

    var words = toWords(num);
    

    Using jQuery, you can wrap this inside of 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

    0 讨论(0)
  • 2020-12-06 08:08

    Should check the source of this example, with some modification you should be able to achieve this:

    http://abhisanoujam.blogspot.com/2009/07/having-fun-with-jquery-numbers-to-words.html

    0 讨论(0)
  • 2020-12-06 08:18

    Here is a Javascript solution that's both compact and working well:

    Number to Words

    It can be used like this:

    var words = toWords(num);
    
    0 讨论(0)
  • 2020-12-06 08:20
    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 讨论(0)
提交回复
热议问题