求一个将阿拉伯数字转换为美元大写的代码或函数。。。

qq_35012205 2016-05-16 12:22:17
求一个将阿拉伯数字转换为美元大写的代码或函数。。。
...全文
733 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2016-05-30
  • 打赏
  • 举报
回复
million,billion后面直接出现几十或几也得加and吧。
lm_whales 2016-05-29
  • 打赏
  • 举报
回复
1005 ==One thousand and five 105 ==One hundred and five 155==One hundred and fifty-five 100155 ==One hundred thousand one hundred and fifty-five 101155 ==One hundred and one thousand one hundred and fifty-five 就是 千百 加上几十,几个都要and 他们是12进制,+百进制+千进制 ;三种进制 一百以内的数和 千百在一起需要 and
赵4老师 2016-05-23
  • 打赏
  • 举报
回复
是不是只要在每个hundred后面,且紧跟几十或几的前面,加" and "就行了?
lm_whales 2016-05-21
  • 打赏
  • 举报
回复
引用 2 楼 zhao4zhong1 的回复:
仅供参考:

。。。。
    return 0;
}
//                  0 is [zero]
//                  1 is [one]
//                  9 is [nine]
//                 19 is [nineteen]
//                 20 is [twenty]
//                 21 is [twenty one]
//                 90 is [ninety]
//                100 is [one hundred]
//               2000 is [two thousand]
//            3000000 is [three million]
//         4000000000 is [four billion]
//1000000000000000002 is [one billion billion two]
//1234567890123456789 is [one billion two hundred thirty four million five hundred sixty seven thousand eight hundred ninety billion one hundred twenty three million four hundred fifty six thousand seven hundred eighty nine]
//9223372036854775807 is [nine billion two hundred twenty three million three hundred seventy two thousand thirty six billion eight hundred fifty four million seven hundred seventy five thousand eight hundred seven]
//
有木有觉得在本ID的嘴里“仅供参考”就和“芝麻开门”一样灵验?
忘了说了,适当的地方,加上 and
lm_whales 2016-05-21
  • 打赏
  • 举报
回复
引用 2 楼 zhao4zhong1 的回复:
仅供参考:
#pragma warning(disable:4996)
#include <stdio.h>
char *NUMBERS_UP_TO_20[] ={
    "zero"   ,"one"    ,"two"     ,"three"   ,"four"    ,
    "five"   ,"six"    ,"seven"   ,"eight"   ,"nine"    ,
    "ten"    ,"eleven" ,"twelve"  ,"thirteen","fourteen",
    "fifteen","sixteen","sventeen","eighteen","nineteen",
};
char *NUMBERS_MULTIPLE_OF_10[] ={
    "twenty", "thirty" , "fourty", "fifty" ,
    "sixty" , "seventy", "eighty", "ninety",
};
char *NumberToString(long long int nNum,char *p) {
    char *q;
    int n;
    long long int nCrntNumber;

    q=p;
    if (nNum<0) return "";
    if (nNum<20) return NUMBERS_UP_TO_20[nNum];

    nCrntNumber=nNum/1000000000;
    if (nCrntNumber>0) {
        n=sprintf(p,"%s billion ",NumberToString(nCrntNumber,p));
        p+=n;
        nNum%=1000000000;
    }

    nCrntNumber=nNum/1000000;
    if (nCrntNumber>0) {
        n=sprintf(p,"%s million ",NumberToString(nCrntNumber,p));
        p+=n;
        nNum%=1000000;
    }

    nCrntNumber=nNum/1000;
    if (nCrntNumber>0) {
        n=sprintf(p,"%s thousand ",NumberToString(nCrntNumber,p));
        p+=n;
        nNum%=1000;
    }

    nCrntNumber=nNum/100;
    if (nCrntNumber>0) {
        n=sprintf(p,"%s hundred ",NumberToString(nCrntNumber,p));
        p+=n;
        nNum%=100;
    }

    if (0<nNum && nNum<20) {
        n=sprintf(p,"%s ",NumberToString(nNum,p));
        p+=n;
    } else {
        nCrntNumber=nNum/10;
        if (nCrntNumber>0) {
            n=sprintf(p,"%s ",NUMBERS_MULTIPLE_OF_10[nCrntNumber-2]);
            p+=n;
            nNum%=10;
        }

        nCrntNumber=nNum;
        if (nCrntNumber>0) {
            n=sprintf(p,"%s ",NumberToString(nCrntNumber,p));
            p+=n;
        }
    }

    if (p[-1]==' ') p[-1]=0;

    return q;
}
int main() {
    char sRes[256];
    long long int d;

    d=                  0  ;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));
    d=                  1  ;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));
    d=                  9  ;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));
    d=                 19  ;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));
    d=                 20  ;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));
    d=                 21  ;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));
    d=                 90  ;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));
    d=                100  ;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));
    d=               2000  ;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));
    d=            3000000  ;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));
    d=         4000000000ll;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));
    d=1000000000000000002ll;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));
    d=1234567890123456789ll;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));
    d=9223372036854775807ll;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));//2^63-1
    return 0;
}
//                  0 is [zero]
//                  1 is [one]
//                  9 is [nine]
//                 19 is [nineteen]
//                 20 is [twenty]
//                 21 is [twenty one]
//                 90 is [ninety]
//                100 is [one hundred]
//               2000 is [two thousand]
//            3000000 is [three million]
//         4000000000 is [four billion]
//1000000000000000002 is [one billion billion two]
//1234567890123456789 is [one billion two hundred thirty four million five hundred sixty seven thousand eight hundred ninety billion one hundred twenty three million four hundred fifty six thousand seven hundred eighty nine]
//9223372036854775807 is [nine billion two hundred twenty three million three hundred seventy two thousand thirty six billion eight hundred fifty four million seven hundred seventy five thousand eight hundred seven]
//
有木有觉得在本ID的嘴里“仅供参考”就和“芝麻开门”一样灵验?
收藏了
赵4老师 2016-05-16
  • 打赏
  • 举报
回复
仅供参考:
#pragma warning(disable:4996)
#include <stdio.h>
char *NUMBERS_UP_TO_20[] ={
    "zero"   ,"one"    ,"two"     ,"three"   ,"four"    ,
    "five"   ,"six"    ,"seven"   ,"eight"   ,"nine"    ,
    "ten"    ,"eleven" ,"twelve"  ,"thirteen","fourteen",
    "fifteen","sixteen","sventeen","eighteen","nineteen",
};
char *NUMBERS_MULTIPLE_OF_10[] ={
    "twenty", "thirty" , "fourty", "fifty" ,
    "sixty" , "seventy", "eighty", "ninety",
};
char *NumberToString(long long int nNum,char *p) {
    char *q;
    int n;
    long long int nCrntNumber;

    q=p;
    if (nNum<0) return "";
    if (nNum<20) return NUMBERS_UP_TO_20[nNum];

    nCrntNumber=nNum/1000000000;
    if (nCrntNumber>0) {
        n=sprintf(p,"%s billion ",NumberToString(nCrntNumber,p));
        p+=n;
        nNum%=1000000000;
    }

    nCrntNumber=nNum/1000000;
    if (nCrntNumber>0) {
        n=sprintf(p,"%s million ",NumberToString(nCrntNumber,p));
        p+=n;
        nNum%=1000000;
    }

    nCrntNumber=nNum/1000;
    if (nCrntNumber>0) {
        n=sprintf(p,"%s thousand ",NumberToString(nCrntNumber,p));
        p+=n;
        nNum%=1000;
    }

    nCrntNumber=nNum/100;
    if (nCrntNumber>0) {
        n=sprintf(p,"%s hundred ",NumberToString(nCrntNumber,p));
        p+=n;
        nNum%=100;
    }

    if (0<nNum && nNum<20) {
        n=sprintf(p,"%s ",NumberToString(nNum,p));
        p+=n;
    } else {
        nCrntNumber=nNum/10;
        if (nCrntNumber>0) {
            n=sprintf(p,"%s ",NUMBERS_MULTIPLE_OF_10[nCrntNumber-2]);
            p+=n;
            nNum%=10;
        }

        nCrntNumber=nNum;
        if (nCrntNumber>0) {
            n=sprintf(p,"%s ",NumberToString(nCrntNumber,p));
            p+=n;
        }
    }

    if (p[-1]==' ') p[-1]=0;

    return q;
}
int main() {
    char sRes[256];
    long long int d;

    d=                  0  ;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));
    d=                  1  ;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));
    d=                  9  ;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));
    d=                 19  ;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));
    d=                 20  ;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));
    d=                 21  ;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));
    d=                 90  ;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));
    d=                100  ;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));
    d=               2000  ;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));
    d=            3000000  ;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));
    d=         4000000000ll;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));
    d=1000000000000000002ll;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));
    d=1234567890123456789ll;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));
    d=9223372036854775807ll;printf("%19lld is [%s]\n",d,NumberToString(d,sRes));//2^63-1
    return 0;
}
//                  0 is [zero]
//                  1 is [one]
//                  9 is [nine]
//                 19 is [nineteen]
//                 20 is [twenty]
//                 21 is [twenty one]
//                 90 is [ninety]
//                100 is [one hundred]
//               2000 is [two thousand]
//            3000000 is [three million]
//         4000000000 is [four billion]
//1000000000000000002 is [one billion billion two]
//1234567890123456789 is [one billion two hundred thirty four million five hundred sixty seven thousand eight hundred ninety billion one hundred twenty three million four hundred fifty six thousand seven hundred eighty nine]
//9223372036854775807 is [nine billion two hundred twenty three million three hundred seventy two thousand thirty six billion eight hundred fifty four million seven hundred seventy five thousand eight hundred seven]
//
有木有觉得在本ID的嘴里“仅供参考”就和“芝麻开门”一样灵验?
lm_whales 2016-05-16
  • 打赏
  • 举报
回复
引用 楼主 qq_35012205 的回复:
求一个将阿拉伯数字转换为美元大写的代码或函数。。。
? 这话怎么说啊 转换为美语(美式英语)? 好像不能直接拿数字换美元? 可以用 人民币,英镑 等等 这一类的 货币直接兑换 如果 仅仅是是美元的表示,加个 $ 即可 $ 5,$100 这种便是 美语 要变成 five $,a hundred $ 这种吧 考虑到都是用的数字 冠词 换成数字吧 one hundred $ 主要麻烦是,要考虑单位 百,千,兆 ,。。。。。 国外,一般大数字 。用千进制单位thousand,million,billion,trillion 注意美国和英国billion 含义有所不同哦 国内 万进制单位 万,亿,万亿,亿亿 过去 有 十万为亿,十亿为兆的用法,这是 十进制,所有单位都是十进制。 也有万万为亿,万亿为兆的用法,这是万进制,万以后的大数,采用万进制。 不过,现在 兆以上的不用了 兆 用作百万了,是十进制的

3,881

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 其它技术问题
社区管理员
  • 其它技术问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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