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;
}
}
}
查看全文
相关阅读:
python2 与python3 区别的总结 持续更新中......
基础数据类型初识(三)字典
基础数据类型初识(二)列表,元组
基本数据类型初识(一)数字,字符串
python基础知识(理论)
进程池 和 管道 , 进程之间的 信息共享
并发编程
进程 和 多进程
计算机系统的发展史
网络编程 黏包
原文地址:https://www.cnblogs.com/sasbya/p/951987.html
最新文章
精通 Grails: 用 JSON 和 Ajax 实现异步 Grails(转载)
JavaScript定时机制、以及浏览器渲染机制(转载)
Silverlight json 通信
JS异步顺序执行
WCF信道的自动关闭或中断
关于Linux中的 localhost 默认地址简单介绍
python编程系列---多个装饰器装饰一个函数的执行流程
Python编程系列---装饰器执行的底层原理及流程
Python编程系列---Python中装饰器的几种形式及万能装饰器
python编程系列---白痴女朋友(我没有女朋友!)看了都能懂的TCP/IP协议介绍
热门文章
python编程系列---global的使用注意点
{每日一题}:四种方法实现打印feibo斐波那契数列
python编程系列---可迭代对象,迭代器和生成器详解
python编程系列---args与kwargs详解
python编程系列---进程池的优越性体验
迭代器,生成器,列表推导式,生成器表达式
装饰器
函数初识
python内部文件的传输与存储
面试题持续更新中......
Copyright © 2011-2022 走看看