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;
}
}
}
查看全文
相关阅读:
css实现自适应正方形
遇到稍微复杂的场景发现css功力不足
聊聊缓存
git学习笔记
font-size:0的作用
移动端高清屏适配方案
react生命周期
javascript写定时器
js判断字符串是否以某个字符串开头和js分解字符串
json.parse()和json.stringify()
原文地址:https://www.cnblogs.com/sasbya/p/951987.html
最新文章
visuabox填坑之设置共享文件夹
简说linux
上班有点时间,怎样把碎片时间用来学python
为了python准备一些软件
python知识梳理(学前准备)
为python开通的一个博客,希望能步入老年的自己成为极客
Java Web前后端交互方式 传值方式等研究
Session、Cookie、SSO等不同登录机制研究
Dubbox架构解读
好习惯养成记
热门文章
面试题以及解答
MySql并发插入导致死锁问题
C语言 学生管理系统
Web前端——jQuery----细节
电脑技巧——系统安装
专业基础——疑词解惑
电脑技巧——常用命令大全
编程语言——C----细节
电脑技巧——DOS和windows的区别?
JSSDK中getLocalImgData的用法
Copyright © 2011-2022 走看看