zoukankan
html css js c++ java
数字翻译成英语
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <script type="text/javascript"><!-- var arr1=new Array(""," thousand"," million"," billion") var arr2=new Array("zero","ten","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety") var arr3=new Array("zero","one","two","three","four","five","six","sever","eight","nine"); var arr4=new Array("ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"); function Translate(num){ var len=num.length,i,j=0,strRet=""; var cols=Math.ceil(len/3); var first=len-cols*3 var strRet="" for(i=first;i<len;i+=3){ ++j; if(i>=0) num3=num.substring(i,i+3) else num3=num.substring(0,first+3) strEng=English(num3) if(strEng!=""){ if(strRet!="") strRet+="," strRet+=English(num3)+arr1[cols-j] } } return strRet } function English(num){ strRet="" if((num.length==3)&&(num.substr(0,3)!="000")){ if((num.substr(0,1)!="0")){ strRet+=arr3[num.substr(0,1)]+" hundred" if(num.substr(1,2)!="00")strRet+=" and " } num=num.substring(1); } if((num.length==2)){ if((num.substr(0,1)=="0")){ num=num.substring(1) } else if((num.substr(0,1)=="1")){ strRet+=arr4[num.substr(1,2)] } else{ strRet+=arr2[num.substr(0,1)] if(num.substr(1,1)!="0")strRet+="-" num=num.substring(1) } } if((num.length==1)&&(num.substr(0,1)!="0")){ strRet+=arr3[num.substr(0,1)] } return strRet; } // --></script> </HEAD> <BODY> <input id=number value=1234567890><input type=button value=翻译成英文 onclick=alert(Translate(document.all.number.value))> </BODY> </HTML>
运行代码
查看全文
相关阅读:
迭代器(iterator)
Vector/Push_back
fprintf()、sprintf()、printf()、fwrite()函数的用法与区别
快速删除node_modules的方法
iView动态生成Menu时open-names不生效的解决办法
CSS3绘制各类图形总结
Node在一线企业中的运用(转)
content属性为中文时导致html页面乱码问题
深入理解CSS:line-height、vertical-align
npm私有仓库(基于nexus2搭建)使用手册
原文地址:https://www.cnblogs.com/geass/p/1951484.html
最新文章
vs2013转为vs2010项目
php数组转为字符串,数据库存储
设计模式 -- Abstract Factory 抽象工厂
[SQL]1211
[SQL]1164 又是被主键坑了的一天
[SQL]返回最大值的两道题:1076(返回的最大值所在列需要自己创造)+1077(另一张表中的分组返回最大值)
[SQL]1070 特别玄学的一道题
[SQL]602(根据属性判定Root/Inner/Leaf)+612(两两距离)
[SQL]给定数字的频率查询中位数
[SQL]1251
热门文章
[SQL]1045(JOIN)+603(abs, JOIN)
[SQL]597(表2行数/表1行数)+602(表的上下拼接)
[SQL]586(输出某特性众数的对应ID)+585(两个临时表的差)
浅谈CPU、内存、硬盘之间的关系
卷积
MLS(移动最小二乘)
内存管理(堆、栈、自由存储区、全局/静态存储区和常量存储区)
C++的virtual详解
struct tm
Difftime
Copyright © 2011-2022 走看看