Number to Word - jquery
Anyone know's a way 开发者_Go百科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:
description will be "one million two hundred "
Thanks!
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
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
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);
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.
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');
});
}
精彩评论