社区
Web 开发
帖子详情
请问:如何将阿拉伯数字转化为英语来表达!
kevin214
2003-08-25 02:30:39
请问:如何将阿拉伯数字转化为英语来表达!
如:494368.00 转化为
Four Hundred and Ninety Four Thousand Three Hundredand Sixty Eight Only.
希望高手指点,谢谢!
...全文
180
6
打赏
收藏
请问:如何将阿拉伯数字转化为英语来表达!
请问:如何将阿拉伯数字转化为英语来表达! 如:494368.00 转化为 Four Hundred and Ninety Four Thousand Three Hundredand Sixty Eight Only. 希望高手指点,谢谢!
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
6 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
kevin214
2003-08-29
打赏
举报
回复
我也是没有办法啊!谢谢各位了!尤其是AngusZhang(zhgapp),再次表示感谢!
huangry
2003-08-26
打赏
举报
回复
说实话 我也觉得楼主的这种问题... ...
AngusZhang
2003-08-26
打赏
举报
回复
package com.str;
import java.math.BigDecimal;
/**
* @author AngusZhang
*/
public class EnglishDecimalFormat {
private static final String[] text = new String[10];
static {
text[0] = "zero";
text[1] = "one";
text[2] = "two";
text[3] = "three";
text[4] = "four";
text[5] = "five";
text[6] = "six";
text[7] = "seven";
text[8] = "eight";
text[9] = "nine";
}
private static final String[] majorNames =
{
"",
" thousand",
" million",
" billion",
" trillion",
" quadrillion",
" quintillion" };
private static final String[] tensNames =
{
"",
" ten",
" twenty",
" thirty",
" fourty",
" fifty",
" sixty",
" seventy",
" eighty",
" ninety" };
private static final String[] numNames =
{
"",
" one",
" two",
" three",
" four",
" five",
" six",
" seven",
" eight",
" nine",
" ten",
" eleven",
" twelve",
" thirteen",
" fourteen",
" fifteen",
" sixteen",
" seventeen",
" eighteen",
" nineteen" };
private static String convertLessThanOneThousand(int number) {
String soFar;
if (number % 100 < 20) {
soFar = numNames[number % 100];
number /= 100;
}
else {
soFar = numNames[number % 10];
number /= 10;
soFar = tensNames[number % 10] + soFar;
number /= 10;
}
if (number == 0)
return soFar;
return numNames[number] + " hundred" + soFar;
}
public static String convert(int number) {
/* special case */
if (number == 0) {
return "zero";
}
String prefix = "";
if (number < 0) {
number = -number;
prefix = "negative";
}
String soFar = "";
int place = 0;
do {
int n = number % 1000;
if (n != 0) {
String s = convertLessThanOneThousand(n);
soFar = s + majorNames[place] + soFar;
}
place++;
number /= 1000;
}
while (number > 0);
return (prefix + soFar).trim();
}
/**
* Date: 2003-5-30
* Time: 13:02:16
* @author kangpeng
* @param big
* @return String
*/
public static String convertNumber(BigDecimal big) {
String rValue = "";
double or = big.doubleValue();
if (or == 0.0) {
rValue = "zero";
}
else {
String orS = "" + or;
int indexByZero = orS.indexOf(".");
String integer = orS.substring(0, indexByZero);
String point = orS.substring(indexByZero + 1);
String pointValue = "";
for (int i = 0, len = point.length(); i < len; i++) {
int x = Integer.parseInt(point.substring(i, i + 1));
pointValue += text[x] + " ";
}
if (pointValue.length() > 2) {
pointValue = " point " + pointValue;
}
rValue = convert(Integer.parseInt(integer)) + pointValue;
}
return rValue;
}
public static void main(String[] args) {
EnglishDecimalFormat f = new EnglishDecimalFormat();
System.out.println("*** " + f.convert(0));
System.out.println("*** " + f.convert(1));
System.out.println("*** " + f.convert(16));
System.out.println("*** " + f.convert(100));
System.out.println("*** " + f.convert(118));
System.out.println("*** " + f.convert(200));
System.out.println("*** " + f.convert(219));
System.out.println("*** " + f.convert(800));
System.out.println("*** " + f.convert(801));
System.out.println("*** " + f.convert(1316));
System.out.println("*** " + f.convert(1000000));
System.out.println("*** " + f.convert(2000000));
System.out.println("*** " + f.convert(3000200));
System.out.println("*** " + f.convert(700000));
System.out.println("*** " + f.convert(9000000));
System.out.println("*** " + f.convert(123456789));
System.out.println("*** " + f.convertNumber(new BigDecimal(12345.6789)));
System.out.println("*** " + f.convert(-45));
/*
*** zero
*** one
*** sixteen
*** one hundred
*** one hundred eighteen
*** two hundred
*** two hundred nineteen
*** eight hundred
*** eight hundred one
*** one thousand three hundred sixteen
*** one million
*** two million
*** three million two hundred
*** seven hundred thousand
*** nine million
*** one hundred twenty three million four hundred fifty six thousand seven hundred eighty nine
*** negative fourty five
*/
}
}
fft123
2003-08-26
打赏
举报
回复
先挨个substring
然后判断位数
最后4-->four,9-->Ninety ................................
太麻烦了
不知道楼主为什么要这样做
不会又是什么bt客户的bt需求吧
ticlej
2003-08-26
打赏
举报
回复
不是分够不够的问题,楼主的问题,其实并没有太多的难度,只需要你有耐心.估计要自己写罗.
也就是通过字符串分位读取了.
kevin214
2003-08-26
打赏
举报
回复
有高手会吗?分不够可以再加!谢谢了!
Excel函数活用范例大辞典(全新版).何先军.2015-2(带书签高清文字版).pdf
159 将英文句子的首字母转换为大写其余小写的形式 318 160 将所有单词转换为大写 320 161 统计软件名称中英文字母的个数 321 162 将区域中的文本串联 323 163 为公式添加说明 324 164 用简易图表表示...
Python
阿拉伯数字
转换成英文
今天需要用到将
阿拉伯数字
转换成英文(读音一样的)功能,百度也没有找到合适的程序,只能自己写一个了. 因为看了不少代码的例子,有一篇里面有一个’递归’,让我刚开始走了偏路(可能是真的能递归, 也可能他写的是汉字的)...
阿拉伯数字
转换成英文以及中文
表达
把一串数字装换成英文
表达
或者中文
表达
。 例如:1234转换成一千二百三十四和one southand two hundred thirty four 思路分析 此题就是纯coding问题,不过,需要注意一个特殊技巧,那就是,类似于职责链模式一样的...
python
阿拉伯数字
转换为英文,python将英文单词表示的数字转换成
阿拉伯数字
的代码...
import re_known = {'zero': 0,'one': 1,'two': 2,'three': 3,'four': 4,'five': 5,'six': 6,'seven': 7,'eight': 8,'nine': 9,'ten': 10,'eleven': 11,'twelve': 12,'thirteen': 13,'fourteen': 14,'fifteen': 15,'...
数字转换
英语
c语言程序,C语言编写的
英语
数字
转化
代码(数字
转化
为用
英语
表达
的数字).doc...
C语言编写的
英语
数字
转化
代码(数字
转化
为用
英语
表达
的数字)#include"stdio.h"main (){FILE *fp ;int i ,n ,g,s;char *a[20]={"zero","one","two","three","four","five","six","seven","eight","nine ","ten",...
Web 开发
81,092
社区成员
341,718
社区内容
发帖
与我相关
我的任务
Web 开发
Java Web 开发
复制链接
扫一扫
分享
社区描述
Java Web 开发
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章