zoukankan
html css js c++ java
咱也写个小写数字转大写金额 ,纯粹字符串操作实现
纯粹字符串操作实现
using
System;
using
System.Collections.Generic;
using
System.Text;
namespace
ConsoleApplication1
{
class
Program
{
static
void
Main(
string
[] args)
{
Console.Write(
"
输入任意数字,回车转换
"
);
Console.Write(
"
\r\n
"
);
Console.Write(
"
直接回车则退出
"
);
Console.Write(
"
\r\n
"
);
for
(; ; )
{
string
tmpString
=
Console.ReadLine();
if
(tmpString.Trim()
==
string
.Empty)
{
break
;
}
try
{
Console.Write(
string
.Format(
"
{0} \r\n
"
, ConvertNumberToChineseNumber(tmpString)));
}
catch
(Exception ex)
{
Console.Write(ex.Message);
}
}
}
/**/
///
<summary>
///
数字转大写金额
///
</summary>
///
<param name="targetString">
数字
</param>
///
<returns>
大写金额
</returns>
private
static
string
ConvertNumberToChineseNumber(
string
targetString)
{
string
rtnValue
=
string
.Empty;
double
tmpValue
=
0
;
if
(
double
.TryParse(targetString,
out
tmpValue))
{
rtnValue
=
tmpValue.ToString(
"
#千兆#百兆#拾兆#兆#仟亿#百亿#拾亿#亿#千万#百万#拾万#万#仟#佰#拾#元.#角#分
"
);
}
else
{
throw
new
Exception(
"
输入的不是数字或者过超出范围!
"
);
}
//
去个头
int
firstNumberIndex
=
rtnValue.IndexOfAny(
new
char
[]
{
'
0
'
,
'
1
'
,
'
2
'
,
'
3
'
,
'
4
'
,
'
5
'
,
'
6
'
,
'
7
'
,
'
8
'
,
'
9
'
}
);
if
(firstNumberIndex
>=
0
)
{
rtnValue
=
rtnValue.Substring(firstNumberIndex);
}
//
去小数点或去个尾
int
lastNumberIndex
=
rtnValue.LastIndexOfAny(
new
char
[]
{
'
0
'
,
'
1
'
,
'
2
'
,
'
3
'
,
'
4
'
,
'
5
'
,
'
6
'
,
'
7
'
,
'
8
'
,
'
9
'
}
);
rtnValue
=
rtnValue.Substring(
0
, lastNumberIndex
+
2
);
//
小写大写切换
rtnValue
=
rtnValue.Replace(
"
.
"
,
""
);
rtnValue
=
rtnValue.Replace(
"
0
"
,
"
零
"
);
rtnValue
=
rtnValue.Replace(
"
1
"
,
"
壹
"
);
rtnValue
=
rtnValue.Replace(
"
2
"
,
"
贰
"
);
rtnValue
=
rtnValue.Replace(
"
3
"
,
"
叁
"
);
rtnValue
=
rtnValue.Replace(
"
4
"
,
"
肆
"
);
rtnValue
=
rtnValue.Replace(
"
5
"
,
"
伍
"
);
rtnValue
=
rtnValue.Replace(
"
6
"
,
"
陆
"
);
rtnValue
=
rtnValue.Replace(
"
7
"
,
"
柒
"
);
rtnValue
=
rtnValue.Replace(
"
8
"
,
"
捌
"
);
rtnValue
=
rtnValue.Replace(
"
9
"
,
"
玖
"
);
return
rtnValue;
}
}
}
查看全文
相关阅读:
[轉]mysql命令大全
[轉]常用MYSQL管理工具收集windows
[轉]Oracle 数据类型及存储方式
[轉]mysql函数集
[轉]Mysqldump备份还原和mysqldump导入导出语句大全详解
JavaScript定义类的几种方式
[轉]NoSQL数据库探讨之一 - 为什么要用非关系数据库?
FLV文件介绍
XAMPP维基百科,自由的百科全书
[轉]dom table
原文地址:https://www.cnblogs.com/sasbya/p/951987.html
最新文章
【Oracle】查历史表里最近七天有多少人留下过登录记录
[轉]PHP5中方法重载的实现研究
[汇總].NET设计模式系列文章
[轉]希腊数学符号与读音对照表
[轉]李开复给家长开出四点育儿妙方
[轉]Smarty模板引擎全教程
[轉]Unicode签名BOM引发的事故
[轉]CSS定义li样式
[轉]五种开源协议的比较(BSD,Apache,GPL,LGPL,MIT)
[轉]PHP字符串过滤需要的函数,安全MYSQL
热门文章
[轉]CDONTS.NewMail发邮件详细篇
軟件版本週期
[轉]PHP与MYSQL的存储过程
MS SQL TRIGGER
[轉]Webdings字体图案
PHP中的魔术方法总结 :__construct,__destruct ,__call,__callStatic,__get,__set,__isset,__unset,__sleep,__wakeup, __toString.......
[轉]Mysql 的 Cascade Restrict
[轉]怎么修改mysql数据库服务器密码
window.showModalDialog()之返回值
常用单证英文名称与简写
Copyright © 2011-2022 走看看