请问:如何将阿拉伯数字转化为英语来表达!

kevin214 2003-08-25 02:30:39
请问:如何将阿拉伯数字转化为英语来表达!
如:494368.00 转化为
Four Hundred and Ninety Four Thousand Three Hundredand Sixty Eight Only.
希望高手指点,谢谢!
...全文
177 6 打赏 收藏 转发到动态 举报
写回复
用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
  • 打赏
  • 举报
回复
有高手会吗?分不够可以再加!谢谢了!

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧