惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
Stack Overflow Blog
Stack Overflow Blog
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
T
The Blog of Author Tim Ferriss
博客园 - 叶小钗
N
Netflix TechBlog - Medium
腾讯CDC
C
Check Point Blog
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
GbyAI
GbyAI
S
SegmentFault 最新的问题
F
Fortinet All Blogs
美团技术团队
U
Unit 42
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 司徒正美
F
Full Disclosure
Recorded Future
Recorded Future
D
DataBreaches.Net
博客园 - 【当耐特】
Martin Fowler
Martin Fowler
J
Java Code Geeks
I
InfoQ
Y
Y Combinator Blog
A
About on SuperTechFans
AI
AI
爱范儿
爱范儿
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Forbes - Security
Forbes - Security
W
WeLiveSecurity
M
MIT News - Artificial intelligence
雷峰网
雷峰网
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
Schneier on Security
Schneier on Security
The GitHub Blog
The GitHub Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
aimingoo的专栏
aimingoo的专栏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
G
GRAHAM CLULEY
Know Your Adversary
Know Your Adversary
Latest news
Latest news
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
D
Docker
Recent Commits to openclaw:main
Recent Commits to openclaw:main
量子位
V2EX - 技术
V2EX - 技术
Project Zero
Project Zero

博客园 - 小小点

发个自己写的分页类 计划+日程表+严格执行 今天开始做事 享受过程 明天失踪一天 加班加班 JS模拟类实现 不能连接MySQL数据库的解决办法 解决安装 MSSQL 提示有挂起的安装问题 [转载] ASP中无组件上传文件 PHP读MYSQL中文乱码的解决方法 自己定义的模仿窗体标题栏的控件 意料之中 DHTML文件访问本地数据库[转] 在b/s开发中经常用到的javaScript技术 [转贴] 关机脚本(转载) 离开... 在MSSQL中利用存储过程进行分页查询 压缩MSSQL数据库日志文件大小
使用 C# 将数字转换成大写人民币
小小点 · 2008-05-11 · via 博客园 - 小小点

贴段最近在项目中用到的一个函数.
因涉及到财务,需要把数字符转换成大写人民币汉字,于是自己动手写了一个,使用的算法比较笨,各位看客不要笑啊.
可转换数字大小在10亿以下,超过的,就无能为力了,不过大家可以自己扩充它.

// Created By 小点 at 2008-5-3
// QQ:28043566  Email:whhq84#163.com(发邮件时请换#为@)
// 大家可随意转载,更欢迎与我交流!

/// <summary>
/// 将数字转换成大写人民币
/// </summary>
/// <param name="v">要转换的数字字符串</param>
/// <returns>转换后的大写人民币字符串</returns>
private static string Num2Char(string var)
{
 string retval = "";
 bool IsPoint = false;
 double v = double.Parse(var);
 if (v > 0)
 {
  char[] chars = v.ToString().ToCharArray();
  foreach (char c in chars)
  {
   IsPoint = false;
   switch (c)
   {
    case '1': retval += "壹"; break;
    case '2': retval += "贰"; break;
    case '3': retval += "叁"; break;
    case '4': retval += "肆"; break;
    case '5': retval += "伍"; break;
    case '6': retval += "陆"; break;
    case '7': retval += "柒"; break;
    case '8': retval += "捌"; break;
    case '9': retval += "玖"; break;
    case '0': retval += "零"; break;
    default: IsPoint = true; break;
   }
   if (!IsPoint)
   {
    v = v / 10;
    if (v > 0.001 && v < 0.009999999999)
    {
     retval += "分";
    }
    else if (v > 0.01 && v < 0.099999999999)
    {
     retval += "角";
    }
    else if (v > 0.1 && v < 0.999999999999)
    {
     retval += "元";
    }
    else if (v > 1 && v < 9.999999999999)
    {
     retval += "拾";
    }
    else if (v > 10 && v < 99.999999999999)
    {
     retval += "佰";
    }
    else if (v > 100 && v < 999.999999999999)
    {
     retval += "仟";
    }
    else if (v > 1000 && v < 9999.999999999999)
    {
     retval += "万";
    }
    else if (v > 10000 && v < 99999.999999999999)
    {
     retval += "拾";
    }
    else if (v > 100000 && v < 999999.999999999999)
    {
     retval += "佰";
    }
    else if (v > 1000000 && v < 9999999.999999999999)
    {
     retval += "仟";
    }
    else if (v > 10000000 && v < 99999999.999999999999)
    {
     retval += "亿";
    }
   }
  }
 }
 else
 {
  retval = "零";
 }
 return retval;
}