用于将数字转换为字符串的javascript代码 Μy代码不会将数字转换为单词。有什么错误吗?django中的表单相关问题
用于将数字转换为字符串的javascript代码 Μy代码不会将数字转换为单词。有什么错误吗?django中的表单相关问题,javascript,jquery,Javascript,Jquery,$(文档).ready(函数(){ $(“#金额”).keyup(函数(){ $(“#amount_string”).val(Number($(“#amount”).val()).toString()); }); }); 名称: 日期: 金额: 大写金额: 如果您想:2将显示为“2” 那么代码应该是这样的……注意(使用我们的代码世界代码) $(文档).ready(函数(){ $(“#金额”).keyup(函数(){ 警惕(“来”); var word=numbertoWord($(“#amoun
$(文档).ready(函数(){
$(“#金额”).keyup(函数(){
$(“#amount_string”).val(Number($(“#amount”).val()).toString());
});
});
名称:
日期:
金额:
大写金额:
如果您想:2将显示为“2”
那么代码应该是这样的……注意(使用我们的代码世界代码)
$(文档).ready(函数(){
$(“#金额”).keyup(函数(){
警惕(“来”);
var word=numbertoWord($(“#amount”).val();
警惕(word);
});
函数编号字(n){
var string=n.toString(),
单位、十、刻度、开始、结束、块、块、块、整数、i、单词、单词;
var和=“| |”和“;
if(parseInt(string)==0){
返回“零”;
}
单位=[“‘一’、‘二’、‘三’、‘四’、‘五’、‘六’、‘七’、‘八’、‘九’、‘十’、‘十一’、‘十二’、‘十三’、‘十四’、‘十五’、‘十六’、‘十七’、‘十八’、‘十九’”;
十=[''、'二十'、'三十'、'四十'、'五十'、'六十'、'七十'、'八十'、'九十'];
尺度=[“千”、“百万”、“十亿”、“万亿”];
start=string.length;
块=[];
while(开始>0){
结束=开始;
push(string.slice((start=Math.max(0,start-3)),end));
}
chunksLen=chunks.length;
如果(chunksLen>缩放长度){
返回“”;
}
单词=[];
对于(i=0;i
编码快乐 看起来它在您的示例中有效。“一个词”叫什么?当我输入“33”时,它工作,但“33a”是NaN。对我来说,您的示例将“int”转换为“string”,您的浏览器控制台中是否有任何错误消息?以何种方式不起作用?它应该做什么,它实际上做了什么?是否有错误消息?看。我想当你说“变成文字”时,你的意思是
55
到“五十五”
?可能是它的有用的mahabub rabbani的副本,但我仍然得到1=1,没有找到我的答案1=1,它正在工作,但在工具栏上显示类似于“come”的通知然后点击它,给出我想要的结果,只在字母字段中,请试着理解我得到了它,塔库,太多了,马哈布·拉巴尼。。。。我今天解决了我最大的问题再次感谢。。它能按照我的要求正常工作。嘿,马哈布·拉巴尼,你能告诉我,我是如何在南亚的数字系统中,如湖泊、克罗尔等,改变音阶单词,来掩盖这个问题的吗。。。。如果您希望看到100万到100万,请根据您的要求更改为loop
if you means to : 2 will show as "two"
then code should be like that...Note(using ourcodeworld code)
$(document).ready(function () {
$("#amount").keyup(function () {
alert("come");
var word = numbertoWord($("#amount").val());
alert(word);
});
function numbertoWord(n) {
var string = n.toString(),
units, tens, scales, start, end, chunks, chunksLen, chunk, ints, i, word, words;
var and = ' ' || 'and';
if (parseInt(string) === 0) {
return 'zero';
}
units = ['', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'];
tens = ['', '', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety'];
scales = ['', 'thousand', 'million', 'billion', 'trillion'];
start = string.length;
chunks = [];
while (start > 0) {
end = start;
chunks.push(string.slice((start = Math.max(0, start - 3)), end));
}
chunksLen = chunks.length;
if (chunksLen > scales.length) {
return '';
}
words = [];
for (i = 0; i < chunksLen; i++) {
chunk = parseInt(chunks[i]);
if (chunk) {
ints = chunks[i].split('').reverse().map(parseFloat);
if (ints[1] === 1) {
ints[0] += 10;
}
if ((word = scales[i])) {
words.push(word);
}
if ((word = units[ints[0]])) {
words.push(word);
}
if ((word = tens[ints[1]])) {
words.push(word);
}
if (ints[0] || ints[1]) {
if (ints[2] || !i && chunksLen) {
words.push(and);
}
}
if ((word = units[ints[2]])) {
words.push(word + ' hundred');
}
}
}
return words.reverse().join(' ');
}
});
otherwise your code is perfect but why you use Number it should look like this
$("#amount_string").val($("#amount").val());