找回密码
 立即注册

QQ登录

只需一步,快速开始

天心天思技术部
金牌服务用户   /  发表于:2023-9-7 11:39  /   查看:783  /  回复:1
请问金额2500要怎样才能设置才能显示成Two Thousand, Five Hundred Dollars Only

1 个回复

倒序浏览
Felix.LiWyn认证
超级版主   /  发表于:2023-9-7 12:30:38
推荐

关于您的问题:如何将金额使用英文展示

这个我们内置确实暂时不行,但是可以使用自定义脚本实现。脚本实现可以参考这个帖子:

https://help.grapecity.com.cn/pa ... tion?pageId=5972510
我这边大概写了一个,您可以试一下:
  1. public string ConvertNumberToWords(int number)
  2.                 {

  3.                         string[] ones = new string[]
  4.                   {
  5.                 "", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine",
  6.                 "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen",
  7.                 "Seventeen", "Eighteen", "Nineteen"
  8.                   };

  9.                         string[] tens = new string[]
  10.                         {
  11.                 "", "", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"
  12.                         };

  13.                         string[] thousands = new string[]
  14.                         {
  15.                 "", "Thousand", "Million", "Billion", "Trillion"
  16.                         };
  17.                         if (number == 0)
  18.                         {
  19.                                 return "Zero";
  20.                         }

  21.                         string words = "";

  22.                         if (number < 0)
  23.                         {
  24.                                 words += "Negative ";
  25.                                 number = Math.Abs(number);
  26.                         }

  27.                         int index = 0;

  28.                         do
  29.                         {
  30.                                 // 取三位数
  31.                                 int num = number % 1000;

  32.                                 if (num != 0)
  33.                                 {
  34.                                         string word = "";

  35.                                         if (num >= 100)
  36.                                         {
  37.                                                 int hundreds = num / 100;
  38.                                                 word += $"{ones[hundreds]} Hundred ";
  39.                                                 num %= 100;
  40.                                         }

  41.                                         if (num >= 20)
  42.                                         {
  43.                                                 int tensDigit = num / 10;
  44.                                                 word += $"{tens[tensDigit]} ";
  45.                                                 num %= 10;
  46.                                         }

  47.                                         if (num > 0)
  48.                                         {
  49.                                                 word += ones[num];
  50.                                         }
  51.                                         string str = word.Trim();
  52.                                         words = $"{str} {thousands[index]} {words}";
  53.                                 }

  54.                                 number /= 1000;
  55.                                 index++;
  56.                         } while (number > 0);

  57.                         return words.Trim()+ " Dollars Only";
  58.                 }
复制代码


我这边做了测试,目前展示正常:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部