Dan*_*iel 7 javascript math jquery
我正在尝试编写一个可以用英语单词进行数学运算的程序.
例如,我希望能够做类似的事情
"four thousand and three" + "seven thousand and twenty nine"
Run Code Online (Sandbox Code Playgroud)
并得到输出
"eleven thousand and thirty two"
Run Code Online (Sandbox Code Playgroud)
是否可以在jQuery中执行此操作?
Pet*_*son 14
是的,我编写了一个名为Word Math的jQuery插件,它是为了这个目的而制作的.
对于您问题中的示例,您只需复制并粘贴此代码即可
alert($.wordMath("four thousand and three").add("seven thousand and twenty nine"));
//alerts "eleven thousand thirty two"
Run Code Online (Sandbox Code Playgroud)
瞧!你已经完成了一些单词数学.
Word Math也可以从Javascript数字转换为单词,反之亦然:
$.wordMath.toString(65401.90332)
// sixty five thousand four hundred one and nine tenths and three thousandths and three ten thousandths and two hundred thousandths
$.wordMath("three million four hundred and sixty seven thousand five hundred and forty two").value
// 3467542
Run Code Online (Sandbox Code Playgroud)
您可以在其自述页面上阅读有关如何使用Word Math插件的更多信息
编辑:现在有一个不依赖于jQuery的Word Math版本.要使用它,您应该wordMath.vanilla.min.js在gitHub存储库而不是文件中下载该wordMath.jquery.js文件.
jQuery-less版本的使用与jQuery版本完全相同,只是$.在调用中不需要前缀.换句话说,而不是做
$.wordMath("fifteen").add("eighteen")
Run Code Online (Sandbox Code Playgroud)
你会改写
wordMath("fifteen").add("eighteen")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
319 次 |
| 最近记录: |